org.springframework.data
spring-data-ldap
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration.java
new file mode 100644
index 0000000000..a8cc1d6467
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.autoconfigure.data.jdbc;
+
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
+import org.springframework.data.jdbc.repository.config.JdbcConfiguration;
+import org.springframework.data.jdbc.repository.config.JdbcRepositoryConfigExtension;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
+
+/**
+ * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's JDBC Repositories.
+ *
+ * Once in effect, the auto-configuration is the equivalent of enabling JDBC repositories
+ * using the
+ * {@link org.springframework.data.jdbc.repository.config.EnableJdbcRepositories}
+ * annotation and providing a {@link JdbcConfiguration} subclass.
+ *
+ * @author Andy Wilkinson
+ * @since 2.1.0
+ * @see EnableJdbcRepositories
+ */
+@Configuration
+@ConditionalOnBean(NamedParameterJdbcOperations.class)
+@ConditionalOnClass({ NamedParameterJdbcOperations.class, JdbcConfiguration.class })
+@ConditionalOnProperty(prefix = "spring.data.jdbc.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
+@AutoConfigureAfter(JdbcTemplateAutoConfiguration.class)
+public class JdbcRepositoriesAutoConfiguration {
+
+ @Configuration
+ @ConditionalOnMissingBean(JdbcRepositoryConfigExtension.class)
+ @Import(JdbcRepositoriesAutoConfigureRegistrar.class)
+ static class JdbcRepositoriesConfiguration {
+
+ }
+
+ @Configuration
+ @ConditionalOnMissingBean(JdbcConfiguration.class)
+ static class SpringBootJdbcConfiguration extends JdbcConfiguration {
+
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigureRegistrar.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigureRegistrar.java
new file mode 100644
index 0000000000..a3e49b0ee2
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigureRegistrar.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.autoconfigure.data.jdbc;
+
+import java.lang.annotation.Annotation;
+
+import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport;
+import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
+import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
+import org.springframework.data.jdbc.repository.config.JdbcRepositoryConfigExtension;
+import org.springframework.data.repository.config.RepositoryConfigurationExtension;
+
+/**
+ * {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data JDBC
+ * Repositories.
+ *
+ * @author Andy Wilkinson
+ */
+class JdbcRepositoriesAutoConfigureRegistrar
+ extends AbstractRepositoryConfigurationSourceSupport {
+
+ @Override
+ protected Class extends Annotation> getAnnotation() {
+ return EnableJdbcRepositories.class;
+ }
+
+ @Override
+ protected Class> getConfiguration() {
+ return EnableJdbcRepositoriesConfiguration.class;
+ }
+
+ @Override
+ protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() {
+ return new JdbcRepositoryConfigExtension();
+ }
+
+ @EnableJdbcRepositories
+ private static class EnableJdbcRepositoriesConfiguration {
+
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/package-info.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/package-info.java
new file mode 100644
index 0000000000..8f52901094
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Auto-configuration for Spring Data JDBC.
+ */
+package org.springframework.boot.autoconfigure.data.jdbc;
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index c370ba38c3..193f9567d4 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -156,6 +156,12 @@
"description": "Whether to enable Elasticsearch repositories.",
"defaultValue": true
},
+ {
+ "name": "spring.data.jdbc.repositories.enabled",
+ "type": "java.lang.Boolean",
+ "description": "Whether to enable JDBC repositories.",
+ "defaultValue": true
+ },
{
"name": "spring.data.jpa.repositories.bootstrap-mode",
"type": "org.springframework.data.repository.config.BootstrapMode",
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
index 946adfbdc2..5a80d1196a 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
@@ -44,6 +44,7 @@ org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoC
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\
+org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java
new file mode 100644
index 0000000000..2c897eb362
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.autoconfigure.data.jdbc;
+
+import javax.sql.DataSource;
+
+import org.junit.Test;
+
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
+import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
+import org.springframework.boot.autoconfigure.data.jdbc.city.City;
+import org.springframework.boot.autoconfigure.data.jdbc.city.CityRepository;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
+import org.springframework.data.jdbc.repository.config.JdbcConfiguration;
+import org.springframework.data.jdbc.repository.config.JdbcRepositoryConfigExtension;
+import org.springframework.data.repository.Repository;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for {@link JdbcRepositoriesAutoConfiguration}.
+ *
+ * @author Andy Wilkinson
+ */
+public class JdbcRepositoriesAutoConfigurationTests {
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withConfiguration(
+ AutoConfigurations.of(JdbcRepositoriesAutoConfiguration.class));
+
+ @Test
+ public void backsOffWithNoDataSource() {
+ this.contextRunner.withUserConfiguration(TestConfiguration.class)
+ .run((context) -> {
+ assertThat(context)
+ .doesNotHaveBean(JdbcRepositoryConfigExtension.class);
+ });
+ }
+
+ @Test
+ public void backsOffWithNoJdbcOperations() {
+ this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
+ TestConfiguration.class).run((context) -> {
+ assertThat(context).hasSingleBean(DataSource.class);
+ assertThat(context)
+ .doesNotHaveBean(JdbcRepositoryConfigExtension.class);
+ });
+ }
+
+ @Test
+ public void basicAutoConfiguration() {
+ this.contextRunner
+ .withConfiguration(
+ AutoConfigurations.of(JdbcTemplateAutoConfiguration.class,
+ DataSourceAutoConfiguration.class))
+ .withUserConfiguration(TestConfiguration.class,
+ EmbeddedDataSourceConfiguration.class)
+ .withPropertyValues(
+ "spring.datasource.schema=classpath:data-jdbc-schema.sql",
+ "spring.datasource.data=classpath:city.sql")
+ .run((context) -> {
+ assertThat(context).hasSingleBean(JdbcConfiguration.class);
+ assertThat(context).hasSingleBean(CityRepository.class);
+ assertThat(context.getBean(CityRepository.class).findById(2000L))
+ .isPresent();
+ });
+ }
+
+ @Test
+ public void autoConfigurationWithNoRepositories() {
+ this.contextRunner
+ .withConfiguration(
+ AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
+ .withUserConfiguration(EmbeddedDataSourceConfiguration.class,
+ EmptyConfiguration.class)
+ .run((context) -> {
+ assertThat(context).hasSingleBean(JdbcConfiguration.class);
+ assertThat(context).doesNotHaveBean(Repository.class);
+ });
+ }
+
+ @Test
+ public void honoursUsersEnableJdbcRepositoriesConfiguration() {
+ this.contextRunner
+ .withConfiguration(
+ AutoConfigurations.of(JdbcTemplateAutoConfiguration.class,
+ DataSourceAutoConfiguration.class))
+ .withUserConfiguration(EnableRepositoriesConfiguration.class,
+ EmbeddedDataSourceConfiguration.class)
+ .withPropertyValues(
+ "spring.datasource.schema=classpath:data-jdbc-schema.sql",
+ "spring.datasource.data=classpath:city.sql")
+ .run((context) -> {
+ assertThat(context).hasSingleBean(JdbcConfiguration.class);
+ assertThat(context).hasSingleBean(CityRepository.class);
+ assertThat(context.getBean(CityRepository.class).findById(2000L))
+ .isPresent();
+ });
+ }
+
+ @TestAutoConfigurationPackage(City.class)
+ private static class TestConfiguration {
+
+ }
+
+ @Configuration
+ @TestAutoConfigurationPackage(EmptyDataPackage.class)
+ protected static class EmptyConfiguration {
+
+ }
+
+ @TestAutoConfigurationPackage(EmptyDataPackage.class)
+ @EnableJdbcRepositories(basePackageClasses = City.class)
+ private static class EnableRepositoriesConfiguration {
+
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/city/City.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/city/City.java
new file mode 100644
index 0000000000..bdec566538
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/city/City.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.autoconfigure.data.jdbc.city;
+
+import org.springframework.data.annotation.Id;
+
+public class City {
+
+ @Id
+ private Long id;
+
+ private String name;
+
+ private String state;
+
+ private String country;
+
+ private String map;
+
+ protected City() {
+ }
+
+ public City(String name, String country) {
+ this.name = name;
+ this.country = country;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getState() {
+ return this.state;
+ }
+
+ public String getCountry() {
+ return this.country;
+ }
+
+ public String getMap() {
+ return this.map;
+ }
+
+ @Override
+ public String toString() {
+ return getName() + "," + getState() + "," + getCountry();
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/city/CityRepository.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/city/CityRepository.java
new file mode 100644
index 0000000000..22f0595388
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/city/CityRepository.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.autoconfigure.data.jdbc.city;
+
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * Data JDBC repository for working with {@link City Cities}.
+ *
+ * @author Andy Wilkinson
+ */
+public interface CityRepository extends CrudRepository {
+
+}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data-jdbc-schema.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data-jdbc-schema.sql
new file mode 100644
index 0000000000..7e3a3462e0
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data-jdbc-schema.sql
@@ -0,0 +1,7 @@
+CREATE TABLE CITY (
+ id INTEGER IDENTITY PRIMARY KEY,
+ name VARCHAR(30),
+ state VARCHAR(30),
+ country VARCHAR(30),
+ map VARCHAR(30)
+);
diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml
index 716ff1fdf2..540566f1cc 100644
--- a/spring-boot-project/spring-boot-dependencies/pom.xml
+++ b/spring-boot-project/spring-boot-dependencies/pom.xml
@@ -355,6 +355,11 @@
spring-boot-starter-data-elasticsearch
${revision}
+
org.springframework.data
spring-data-jpa
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/AutoConfigureDataJdbc.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/AutoConfigureDataJdbc.java
new file mode 100644
index 0000000000..12324b2f50
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/AutoConfigureDataJdbc.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
+
+/**
+ * {@link ImportAutoConfiguration Auto-configuration imports} for typical Data JDBC tests.
+ * Most tests should consider using {@link DataJdbcTest @DataJdbcTest} rather than using
+ * this annotation directly.
+ *
+ * @author Andy Wilkinson
+ * @since 2.1.0
+ * @see DataJdbcTest
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@ImportAutoConfiguration
+public @interface AutoConfigureDataJdbc {
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTest.java
new file mode 100644
index 0000000000..161e6a2f23
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
+import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache;
+import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.core.annotation.AliasFor;
+import org.springframework.core.env.Environment;
+import org.springframework.test.context.BootstrapWith;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+/**
+ * Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
+ * for a typical Data JDBC test. Can be used when a test focuses only on
+ * Data JDBC components.
+ *
+ * Using this annotation will disable full auto-configuration and instead apply only
+ * configuration relevant to Data JDBC tests.
+ *
+ * @author Andy Wilkinson
+ * @since 2.1.0
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@BootstrapWith(DataJdbcTestContextBootstrapper.class)
+@ExtendWith(SpringExtension.class)
+@OverrideAutoConfiguration(enabled = false)
+@TypeExcludeFilters(DataJdbcTypeExcludeFilter.class)
+@AutoConfigureCache
+@AutoConfigureDataJdbc
+@AutoConfigureTestDatabase
+@ImportAutoConfiguration
+public @interface DataJdbcTest {
+
+ /**
+ * Properties in form {@literal key=value} that should be added to the Spring
+ * {@link Environment} before the test runs.
+ * @return the properties to add
+ */
+ String[] properties() default {};
+
+ /**
+ * Determines if default filtering should be used with
+ * {@link SpringBootApplication @SpringBootApplication}. By default no beans are
+ * included.
+ * @see #includeFilters()
+ * @see #excludeFilters()
+ * @return if default filters should be used
+ */
+ boolean useDefaultFilters() default true;
+
+ /**
+ * A set of include filters which can be used to add otherwise filtered beans to the
+ * application context.
+ * @return include filters to apply
+ */
+ Filter[] includeFilters() default {};
+
+ /**
+ * A set of exclude filters which can be used to filter beans that would otherwise be
+ * added to the application context.
+ * @return exclude filters to apply
+ */
+ Filter[] excludeFilters() default {};
+
+ /**
+ * Auto-configuration exclusions that should be applied for this test.
+ * @return auto-configuration exclusions to apply
+ */
+ @AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude")
+ Class>[] excludeAutoConfiguration() default {};
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestContextBootstrapper.java
new file mode 100644
index 0000000000..77c9692933
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestContextBootstrapper.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+import org.springframework.test.context.TestContextBootstrapper;
+
+/**
+ * {@link TestContextBootstrapper} for {@link DataJdbcTest @DataJdbcTest} support.
+ *
+ * @author Andy Wilkinson
+ */
+class DataJdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
+
+ @Override
+ protected String[] getProperties(Class> testClass) {
+ DataJdbcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
+ DataJdbcTest.class);
+ return (annotation != null) ? annotation.properties() : null;
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTypeExcludeFilter.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTypeExcludeFilter.java
new file mode 100644
index 0000000000..5d3e340c7e
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTypeExcludeFilter.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.springframework.boot.context.TypeExcludeFilter;
+import org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizableTypeExcludeFilter;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+
+/**
+ * {@link TypeExcludeFilter} for {@link DataJdbcTest @DataJdbcTest}.
+ *
+ * @author Andy Wilkinson
+ */
+class DataJdbcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
+
+ private final DataJdbcTest annotation;
+
+ DataJdbcTypeExcludeFilter(Class> testClass) {
+ this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
+ DataJdbcTest.class);
+ }
+
+ @Override
+ protected boolean hasAnnotation() {
+ return this.annotation != null;
+ }
+
+ @Override
+ protected Filter[] getFilters(FilterType type) {
+ switch (type) {
+ case INCLUDE:
+ return this.annotation.includeFilters();
+ case EXCLUDE:
+ return this.annotation.excludeFilters();
+ default:
+ throw new IllegalStateException("Unsupported type " + type);
+ }
+ }
+
+ @Override
+ protected boolean isUseDefaultFilters() {
+ return this.annotation.useDefaultFilters();
+ }
+
+ @Override
+ protected Set> getDefaultIncludes() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ protected Set> getComponentIncludes() {
+ return Collections.emptySet();
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/package-info.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/package-info.java
new file mode 100644
index 0000000000..73c617f895
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Auto-configuration for Data JDBC tests.
+ */
+package org.springframework.boot.test.autoconfigure.data.jdbc;
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories
index cbc25286c2..adf105572e 100644
--- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories
@@ -2,6 +2,16 @@
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache=\
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration
+# AutoConfigureDataJdbc auto-configuration imports
+org.springframework.boot.test.autoconfigure.data.jdbc.AutoConfigureDataJdbc=\
+org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
+org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
+org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
+org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
+org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
+org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
+org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
+
# AutoConfigureDataJpa auto-configuration imports
org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa=\
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestIntegrationTests.java
new file mode 100644
index 0000000000..6ecdbff031
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestIntegrationTests.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import javax.sql.DataSource;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
+import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
+import org.springframework.context.ApplicationContext;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.importedAutoConfiguration;
+
+/**
+ * Integration tests for {@link DataJdbcTest}.
+ *
+ * @author Andy Wilkinson
+ */
+@RunWith(SpringRunner.class)
+@DataJdbcTest
+@TestPropertySource(properties = "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/data/jdbc/schema.sql")
+public class DataJdbcTestIntegrationTests {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Autowired
+ private ExampleRepository repository;
+
+ @Autowired
+ private DataSource dataSource;
+
+ @Autowired
+ private ApplicationContext applicationContext;
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ @Test
+ public void testRepository() {
+ this.jdbcTemplate.update(
+ "INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (1, 'a', 'alpha')");
+ this.jdbcTemplate.update(
+ "INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (2, 'b', 'bravo')");
+ assertThat(this.repository.findAll()).hasSize(2);
+ }
+
+ @Test
+ public void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
+ String product = this.dataSource.getConnection().getMetaData()
+ .getDatabaseProductName();
+ assertThat(product).isEqualTo("H2");
+ }
+
+ @Test
+ public void didNotInjectExampleComponent() {
+ this.thrown.expect(NoSuchBeanDefinitionException.class);
+ this.applicationContext.getBean(ExampleComponent.class);
+ }
+
+ @Test
+ public void flywayAutoConfigurationWasImported() {
+ assertThat(this.applicationContext)
+ .has(importedAutoConfiguration(FlywayAutoConfiguration.class));
+ }
+
+ @Test
+ public void liquibaseAutoConfigurationWasImported() {
+ assertThat(this.applicationContext)
+ .has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestPropertiesIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestPropertiesIntegrationTests.java
new file mode 100644
index 0000000000..b10cf67b54
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestPropertiesIntegrationTests.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for the {@link DataJdbcTest#properties properties} attribute of
+ * {@link DataJdbcTest @DataJdbcTest}.
+ *
+ * @author Andy Wilkinson
+ */
+@RunWith(SpringRunner.class)
+@DataJdbcTest(properties = "spring.profiles.active=test")
+public class DataJdbcTestPropertiesIntegrationTests {
+
+ @Autowired
+ private Environment environment;
+
+ @Test
+ public void environmentWithNewProfile() {
+ assertThat(this.environment.getActiveProfiles()).containsExactly("test");
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleComponent.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleComponent.java
new file mode 100644
index 0000000000..477b1a8549
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleComponent.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * Example component used with {@link DataJdbcTest} tests.
+ *
+ * @author Andy Wilkinson
+ */
+@Component
+public class ExampleComponent {
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleDataJdbcApplication.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleDataJdbcApplication.java
new file mode 100644
index 0000000000..cb3b0524eb
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleDataJdbcApplication.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import javax.sql.DataSource;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
+
+/**
+ * Example {@link SpringBootApplication} used with {@link DataJdbcTest} tests.
+ *
+ * @author Andy Wilkinson
+ */
+@SpringBootApplication
+public class ExampleDataJdbcApplication {
+
+ @Bean
+ public DataSource dataSource() {
+ EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
+ .generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL);
+ return builder.build();
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleEntity.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleEntity.java
new file mode 100644
index 0000000000..6b97a3a6f7
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleEntity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import org.springframework.data.annotation.Id;
+
+/**
+ * Example entity used with {@link DataJdbcTest} tests.
+ *
+ * @author Andy Wilkinson
+ */
+public class ExampleEntity {
+
+ @Id
+ private Long id;
+
+ private String name;
+
+ private String reference;
+
+ public ExampleEntity(String name, String reference) {
+ this.name = name;
+ this.reference = reference;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getReference() {
+ return this.reference;
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleRepository.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleRepository.java
new file mode 100644
index 0000000000..3674b883ff
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleRepository.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.test.autoconfigure.data.jdbc;
+
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * Example repository used with {@link DataJdbcTest} tests.
+ *
+ * @author Andy Wilkinson
+ */
+public interface ExampleRepository extends CrudRepository {
+
+}
diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/data/jdbc/schema.sql b/spring-boot-project/spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/data/jdbc/schema.sql
new file mode 100644
index 0000000000..6d144184be
--- /dev/null
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/data/jdbc/schema.sql
@@ -0,0 +1 @@
+create table example_entity (id int, name varchar, reference varchar);
diff --git a/spring-boot-samples/README.adoc b/spring-boot-samples/README.adoc
index d46e5bee0b..a4d77923dc 100644
--- a/spring-boot-samples/README.adoc
+++ b/spring-boot-samples/README.adoc
@@ -50,6 +50,9 @@ The following sample applications are provided:
| link:spring-boot-sample-data-elasticsearch[spring-boot-sample-data-elasticsearch]
| Stores data using Spring Data Elasticsearch
+| link:spring-boot-sample-data-jdbc[spring-boot-sample-data-jdbc]
+| Stores data using Spring Data JDBC
+
| link:spring-boot-sample-data-jpa[spring-boot-sample-data-jpa]
| Stores data using Spring Data JPA with Hibernate
diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml
index 1ce53cdc58..c3c9d36904 100644
--- a/spring-boot-samples/pom.xml
+++ b/spring-boot-samples/pom.xml
@@ -35,6 +35,7 @@
spring-boot-sample-data-cassandra
spring-boot-sample-data-couchbase
spring-boot-sample-data-elasticsearch
+ spring-boot-sample-data-jdbc
spring-boot-sample-data-jpa
spring-boot-sample-data-ldap
spring-boot-sample-data-mongodb
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/pom.xml b/spring-boot-samples/spring-boot-sample-data-jdbc/pom.xml
new file mode 100755
index 0000000000..d1074c312a
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/pom.xml
@@ -0,0 +1,48 @@
+
+
+ 4.0.0
+
+
+ org.springframework.boot
+ spring-boot-samples
+ ${revision}
+
+ spring-boot-sample-data-jdbc
+ Spring Boot Data JDBC Sample
+ Spring Boot Data JDBC Sample
+
+ ${basedir}/../..
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jdbc
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ com.h2database
+ h2
+ runtime
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/Customer.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/Customer.java
new file mode 100644
index 0000000000..709fe2f129
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/Customer.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sample.data.jdbc;
+
+import java.time.LocalDate;
+
+import org.springframework.data.annotation.Id;
+
+class Customer {
+
+ @Id
+ private Long id;
+
+ private String firstName;
+
+ private LocalDate dateOfBirth;
+
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public LocalDate getDateOfBirth() {
+ return this.dateOfBirth;
+ }
+
+ public void setDateOfBirth(LocalDate dateOfBirth) {
+ this.dateOfBirth = dateOfBirth;
+ }
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/CustomerRepository.java
new file mode 100644
index 0000000000..d3d3f522c6
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/CustomerRepository.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sample.data.jdbc;
+
+import java.util.List;
+
+import org.springframework.data.jdbc.repository.query.Query;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.query.Param;
+
+interface CustomerRepository extends CrudRepository {
+
+ @Query("select id, first_name, date_of_birth from customer where upper(first_name) like '%' || upper(:name) || '%' ")
+ List findByName(@Param("name") String name);
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleController.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleController.java
new file mode 100644
index 0000000000..8425f7f31c
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleController.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sample.data.jdbc;
+
+import java.util.List;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+public class SampleController {
+
+ private final CustomerRepository customerRepository;
+
+ public SampleController(CustomerRepository customerRepository) {
+ this.customerRepository = customerRepository;
+ }
+
+ @GetMapping("/")
+ @ResponseBody
+ @Transactional(readOnly = true)
+ public List customers(@RequestParam String name) {
+ return this.customerRepository.findByName(name);
+ }
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleDataJdbcApplication.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleDataJdbcApplication.java
new file mode 100644
index 0000000000..e9ed792a57
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleDataJdbcApplication.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sample.data.jdbc;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SampleDataJdbcApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SampleDataJdbcApplication.class);
+ }
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/data.sql b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/data.sql
new file mode 100644
index 0000000000..4ad90b6b49
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/data.sql
@@ -0,0 +1,2 @@
+INSERT INTO CUSTOMER (ID, FIRST_NAME, DATE_OF_BIRTH) values (1, 'Meredith', '1998-07-13');
+INSERT INTO CUSTOMER (ID, FIRST_NAME, DATE_OF_BIRTH) values (2, 'Joan', '1982-10-29');
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/schema.sql b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/schema.sql
new file mode 100644
index 0000000000..1b999f2e80
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/schema.sql
@@ -0,0 +1,5 @@
+CREATE TABLE CUSTOMER (
+ ID INTEGER IDENTITY PRIMARY KEY,
+ FIRST_NAME VARCHAR(30),
+ DATE_OF_BIRTH DATE
+);
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/CustomerRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/CustomerRepositoryIntegrationTests.java
new file mode 100644
index 0000000000..296ef5199b
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/CustomerRepositoryIntegrationTests.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package sample.data.jdbc;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration tests for {@link CustomerRepository}.
+ *
+ * @author Andy Wilkinson
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureTestDatabase
+public class CustomerRepositoryIntegrationTests {
+
+ @Autowired
+ private CustomerRepository repository;
+
+ @Test
+ public void findAllCustomers() {
+ assertThat(this.repository.findAll()).hasSize(2);
+ }
+
+ @Test
+ public void findByNameWithMatch() {
+ assertThat(this.repository.findByName("joan")).hasSize(1);
+ }
+
+ @Test
+ public void findByNameWithNoMatch() {
+ assertThat(this.repository.findByName("hugh")).isEmpty();
+ }
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/SampleDataJdbcApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/SampleDataJdbcApplicationTests.java
new file mode 100644
index 0000000000..fea4709ab0
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/SampleDataJdbcApplicationTests.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sample.data.jdbc;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * Integration tests for {@link SampleDataJdbcApplication}.
+ *
+ * @author Andy Wilkinson
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SampleDataJdbcApplicationTests {
+
+ @Autowired
+ private WebApplicationContext context;
+
+ private MockMvc mvc;
+
+ @Before
+ public void setUp() {
+ this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
+ }
+
+ @Test
+ public void testCustomers() throws Exception {
+ this.mvc.perform(get("/").param("name", "merEDith")).andExpect(status().isOk())
+ .andExpect(content().string(containsString("Meredith")));
+ }
+
+}