Add support for Spring Data JDBC (auto-config, starter, and test slice)
Closes gh-14489
This commit is contained in:
@@ -659,6 +659,9 @@ content into your application. Rather, pick only the properties that you need.
|
||||
spring.data.elasticsearch.properties.*= # Additional properties used to configure the client.
|
||||
spring.data.elasticsearch.repositories.enabled=true # Whether to enable Elasticsearch repositories.
|
||||
|
||||
# DATA JDBC
|
||||
spring.data.jdbc.repositories.enabled=true # Whether to enable JDBC repositories.
|
||||
|
||||
# DATA LDAP
|
||||
spring.data.ldap.repositories.enabled=true # Whether to enable LDAP repositories.
|
||||
|
||||
|
||||
@@ -3671,7 +3671,7 @@ scenes. If more than one `JdbcTemplate` is defined and no primary candidate exis
|
||||
|
||||
|
||||
[[boot-features-jpa-and-spring-data]]
|
||||
=== JPA and "`Spring Data`"
|
||||
=== JPA and Spring Data JPA
|
||||
The Java Persistence API is a standard technology that lets you "`map`" objects to
|
||||
relational databases. The `spring-boot-starter-data-jpa` POM provides a quick way to get
|
||||
started. It provides the following key dependencies:
|
||||
@@ -3838,6 +3838,23 @@ views. If you do not want this behavior, you should set `spring.jpa.open-in-view
|
||||
|
||||
|
||||
|
||||
[[boot-features-data-jdbc]]
|
||||
=== Spring Data JDBC
|
||||
Spring Data includes repository support for JDBC and will automatically generate SQL for
|
||||
the methods on `CrudRepository`. For more advanced queries, a `@Query` annotation is
|
||||
provided.
|
||||
|
||||
Spring Boot will auto-configure Spring Data's JDBC repositories when the necessary
|
||||
dependencies are on the classpath. They can be added to your project with a single
|
||||
dependency on `spring-boot-starter-data-jdbc`. If necessary, you can take control of
|
||||
Spring Data JDBC's configuration by adding the `@EnableJdbcRepositories` annotation or a
|
||||
`JdbcConfiguration` subclass to your application.
|
||||
|
||||
TIP: For complete details of Spring Data JDBC, please refer to the
|
||||
https://projects.spring.io/spring-data-jdbc/[reference documentation].
|
||||
|
||||
|
||||
|
||||
[[boot-features-sql-h2-console]]
|
||||
=== Using H2's Web Console
|
||||
The http://www.h2database.com[H2 database] provides a
|
||||
@@ -7106,8 +7123,9 @@ following example:
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-jdbc-test]]
|
||||
==== Auto-configured JDBC Tests
|
||||
`@JdbcTest` is similar to `@DataJpaTest` but is for tests that only require a
|
||||
`DataSource`. By default, it configures an in-memory embedded database and a
|
||||
`JdbcTemplate`. Regular `@Component` beans are not loaded into the `ApplicationContext`.
|
||||
`DataSource` and do not use Spring Data JDBC. By default, it configures an in-memory
|
||||
embedded database and a `JdbcTemplate`. Regular `@Component` beans are not loaded into
|
||||
the `ApplicationContext`.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by `@JdbcTest` can be
|
||||
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
|
||||
@@ -7141,6 +7159,29 @@ If you prefer your test to run against a real database, you can use the
|
||||
|
||||
|
||||
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-jdbc-test]]
|
||||
==== Auto-configured Data JDBC Tests
|
||||
`@DataJdbcTest` is similar to `@JdbcTest` but is for tests that use Spring Data JDBC
|
||||
repositories. By default, it configures an in-memory embedded database, a `JdbcTemplate`,
|
||||
and Spring Data JDBD repositories. Regular `@Component` beans are not loaded into
|
||||
the `ApplicationContext`.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by `@DataJdbcTest` can be
|
||||
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
|
||||
|
||||
By default, Data JDBC tests are transactional and roll back at the end of each test. See
|
||||
the {spring-reference}testing.html#testcontext-tx-enabling-transactions[relevant section]
|
||||
in the Spring Framework Reference Documentation for more details. If that is not what you
|
||||
want, you can disable transaction management for a test or for the whole test class as
|
||||
<<boot-features-testing-spring-boot-applications-testing-autoconfigured-jdbc-test,shown
|
||||
in the JDBC example>>.
|
||||
|
||||
If you prefer your test to run against a real database, you can use the
|
||||
`@AutoConfigureTestDatabase` annotation in the same way as for `DataJpaTest`. (See
|
||||
"<<boot-features-testing-spring-boot-applications-testing-autoconfigured-jpa-test>>".)
|
||||
|
||||
|
||||
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-jooq-test]]
|
||||
==== Auto-configured jOOQ Tests
|
||||
You can use `@JooqTest` in a similar fashion as `@JdbcTest` but for jOOQ-related tests.
|
||||
|
||||
Reference in New Issue
Block a user