Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
015d92b8
Commit
015d92b8
authored
Jan 20, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add docs for @EntityScan and JPA repository packages
Fixes gh-200
parent
c1bbd4fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
6 deletions
+37
-6
howto.md
docs/howto.md
+37
-6
No files found.
docs/howto.md
View file @
015d92b8
...
...
@@ -731,19 +731,38 @@ for more details.
Spring Data can create implementations for you of
`@Repository`
interfaces of various flavours. Spring Boot will handle all of that
for you as long as those
`@Repositories`
are included in
a
`@ComponentScan`
.
for you as long as those
`@Repositories`
are included in
the same
package (or a sub-package) of your
`@EnableAutoConfiguration`
class
.
For many applications all you will need is to put the right Spring
Data dependencies on your classpath (there is a
"spring-boot-starter-data-jpa" for JPA and for Mongodb you only nee
dto add "spring-datamongodb"), create some repository interfaces to
handle your
`@Entity`
objects, and then add a
`@ComponentScan`
that
covers those packages. Examples are in the
"spring-boot-starter-data-jpa" for JPA and for Mongodb you only need
to add "spring-datamongodb"), create some repository interfaces to
handle your
`@Entity`
objects. Examples are in the
[
JPA sample
](
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-jpa
)
or the
[
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
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
)
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"
/>
## Discover Built-in Options for External Properties
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment