Add docs for @EntityScan and JPA repository packages
Fixes gh-200
This commit is contained in:
parent
c1bbd4fc4e
commit
015d92b8e8
|
@ -731,19 +731,38 @@ for more details.
|
||||||
|
|
||||||
Spring Data can create implementations for you of `@Repository`
|
Spring Data can create implementations for you of `@Repository`
|
||||||
interfaces of various flavours. Spring Boot will handle all of that
|
interfaces of various flavours. Spring Boot will handle all of that
|
||||||
for you as long as those `@Repositories` are included in a
|
for you as long as those `@Repositories` are included in the same
|
||||||
`@ComponentScan`.
|
package (or a sub-package) of your `@EnableAutoConfiguration` class.
|
||||||
|
|
||||||
For many applications all you will need is to put the right Spring
|
For many applications all you will need is to put the right Spring
|
||||||
Data dependencies on your classpath (there is a
|
Data dependencies on your classpath (there is a
|
||||||
"spring-boot-starter-data-jpa" for JPA and for Mongodb you only nee
|
"spring-boot-starter-data-jpa" for JPA and for Mongodb you only need
|
||||||
dto add "spring-datamongodb"), create some repository interfaces to
|
to add "spring-datamongodb"), create some repository interfaces to
|
||||||
handle your `@Entity` objects, and then add a `@ComponentScan` that
|
handle your `@Entity` objects. Examples are in the
|
||||||
covers those packages. Examples are in the
|
|
||||||
[JPA sample](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-jpa)
|
[JPA sample](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-jpa)
|
||||||
or the
|
or the
|
||||||
[Mongodb sample](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-mongodb).
|
[Mongodb sample](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-mongodb).
|
||||||
|
|
||||||
|
Spring Boot tries to guess the location of your `@Repository`
|
||||||
|
definitions, based on the `@EnableAutoConfiguration` it finds. To get
|
||||||
|
more control, use the `@EnableJpaRepositories` annotation (from Spring
|
||||||
|
Data JPA).
|
||||||
|
|
||||||
|
## Separate @Entity Definitions from Spring Configuration
|
||||||
|
|
||||||
|
Spring Boot tries to guess the location of your `@Entity` definitions,
|
||||||
|
based on the `@EnableAutoConfiguration` it finds. To get more control,
|
||||||
|
you can use the `@EntityScan` annotation, e.g.
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Configuration
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@EntityScan(basePackageClasses=City.class)
|
||||||
|
public class Application {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Configure JPA Properties
|
## Configure JPA Properties
|
||||||
|
|
||||||
Spring JPA already provides some vendor-independent configuration
|
Spring JPA already provides some vendor-independent configuration
|
||||||
|
@ -772,6 +791,18 @@ and
|
||||||
[`JpaBaseConfiguration`](https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java)
|
[`JpaBaseConfiguration`](https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java)
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
|
## Use a Traditional persistence.xml
|
||||||
|
|
||||||
|
Spring doesn't require the use of XML to configure the JPA provider,
|
||||||
|
and Spring Boot assumes you want to take advantage of that feature. If
|
||||||
|
you prefer to use `persistence.xml` then you need to define your own
|
||||||
|
`@Bean` of type `LocalEntityManagerFactoryBean`, and set the
|
||||||
|
persistence unit name there.
|
||||||
|
|
||||||
|
See
|
||||||
|
[`JpaBaseConfiguration`](https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java)
|
||||||
|
for the default settings.
|
||||||
|
|
||||||
<span id="discover.options"/>
|
<span id="discover.options"/>
|
||||||
## Discover Built-in Options for External Properties
|
## Discover Built-in Options for External Properties
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue