From cf4b0e2129f1db7859fd4c25af542cdced0aa366 Mon Sep 17 00:00:00 2001 From: Pavan Shankar Koli Date: Sat, 29 Jun 2019 18:53:11 +0530 Subject: [PATCH] BAEL-2578 Disabling auto configuration --- .../spring-data-jpa/README.md | 3 ++ .../spring-data-jpa/pom.xml | 50 +++++++++++++++++++ .../java/com/baeldung/jpa/SpringDataJPA.java | 15 ++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/logback.xml | 13 +++++ .../jpa/SpringDataJPAIntegrationTest.java | 26 ++++++++++ .../spring-data-mongodb/README.md | 4 ++ .../spring-data-mongodb/pom.xml | 43 ++++++++++++++++ .../baeldung/mongodb/SpringDataMongoDB.java | 15 ++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/logback.xml | 13 +++++ .../SpringDataMongoDBIntegrationTest.java | 25 ++++++++++ .../spring-data-redis/README.md | 4 ++ .../spring-data-redis/pom.xml | 43 ++++++++++++++++ .../com/baeldung/redis/SpringDataRedis.java | 14 ++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/logback.xml | 13 +++++ .../redis/SpringDataRedisIntegrationTest.java | 25 ++++++++++ 18 files changed, 309 insertions(+) create mode 100644 spring-data-disable-auto-configuration/spring-data-jpa/README.md create mode 100644 spring-data-disable-auto-configuration/spring-data-jpa/pom.xml create mode 100644 spring-data-disable-auto-configuration/spring-data-jpa/src/main/java/com/baeldung/jpa/SpringDataJPA.java create mode 100644 spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/application.properties create mode 100644 spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/logback.xml create mode 100644 spring-data-disable-auto-configuration/spring-data-jpa/src/test/java/com/baeldung/jpa/SpringDataJPAIntegrationTest.java create mode 100644 spring-data-disable-auto-configuration/spring-data-mongodb/README.md create mode 100644 spring-data-disable-auto-configuration/spring-data-mongodb/pom.xml create mode 100644 spring-data-disable-auto-configuration/spring-data-mongodb/src/main/java/com/baeldung/mongodb/SpringDataMongoDB.java create mode 100644 spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/application.properties create mode 100644 spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/logback.xml create mode 100644 spring-data-disable-auto-configuration/spring-data-mongodb/src/test/java/com/baeldung/mongodb/SpringDataMongoDBIntegrationTest.java create mode 100644 spring-data-disable-auto-configuration/spring-data-redis/README.md create mode 100644 spring-data-disable-auto-configuration/spring-data-redis/pom.xml create mode 100644 spring-data-disable-auto-configuration/spring-data-redis/src/main/java/com/baeldung/redis/SpringDataRedis.java create mode 100644 spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/application.properties create mode 100644 spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/logback.xml create mode 100644 spring-data-disable-auto-configuration/spring-data-redis/src/test/java/com/baeldung/redis/SpringDataRedisIntegrationTest.java diff --git a/spring-data-disable-auto-configuration/spring-data-jpa/README.md b/spring-data-disable-auto-configuration/spring-data-jpa/README.md new file mode 100644 index 0000000000..23117c9903 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-jpa/README.md @@ -0,0 +1,3 @@ +This module is for Jira BAEL-2578 + +### Relevant Articles: diff --git a/spring-data-disable-auto-configuration/spring-data-jpa/pom.xml b/spring-data-disable-auto-configuration/spring-data-jpa/pom.xml new file mode 100644 index 0000000000..db431fb7fa --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-jpa/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + com.baeldung + spring-data-jpa + 0.0.1-SNAPSHOT + spring-data-jpa + jar + Spring Data with JPA + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + 2.1.6.RELEASE + + + + com.h2database + h2 + 1.4.197 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-jpa/src/main/java/com/baeldung/jpa/SpringDataJPA.java b/spring-data-disable-auto-configuration/spring-data-jpa/src/main/java/com/baeldung/jpa/SpringDataJPA.java new file mode 100644 index 0000000000..bec1b18010 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-jpa/src/main/java/com/baeldung/jpa/SpringDataJPA.java @@ -0,0 +1,15 @@ +package com.baeldung.jpa; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; + +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) +public class SpringDataJPA { + + public static void main(String[] args) { + SpringApplication.run(SpringDataJPA.class, args); + } +} diff --git a/spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/application.properties b/spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/application.properties new file mode 100644 index 0000000000..fc33388896 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/logback.xml b/spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-jpa/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-jpa/src/test/java/com/baeldung/jpa/SpringDataJPAIntegrationTest.java b/spring-data-disable-auto-configuration/spring-data-jpa/src/test/java/com/baeldung/jpa/SpringDataJPAIntegrationTest.java new file mode 100644 index 0000000000..170f60f861 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-jpa/src/test/java/com/baeldung/jpa/SpringDataJPAIntegrationTest.java @@ -0,0 +1,26 @@ +package com.baeldung.jpa; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.sql.DataSource; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringDataJPA.class) +public class SpringDataJPAIntegrationTest { + + @Autowired + private ApplicationContext context; + + @Test(expected = NoSuchBeanDefinitionException.class) + public void givenAutoconfigurationIsDisable_whenApplicationStarts_thenContextWillNotHaveTheAutoconfiguredClasses() { + context.getBean(DataSource.class); + } + +} diff --git a/spring-data-disable-auto-configuration/spring-data-mongodb/README.md b/spring-data-disable-auto-configuration/spring-data-mongodb/README.md new file mode 100644 index 0000000000..b91f5eda5a --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-mongodb/README.md @@ -0,0 +1,4 @@ +This module is for Jira BAEL-2578 + + +### Relevant Articles: diff --git a/spring-data-disable-auto-configuration/spring-data-mongodb/pom.xml b/spring-data-disable-auto-configuration/spring-data-mongodb/pom.xml new file mode 100644 index 0000000000..95bf32545b --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-mongodb/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + com.baeldung + spring-data-mongodb + 0.0.1-SNAPSHOT + spring-data-mongodb + jar + Spring Data with MongoDB + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-mongodb + 2.1.6.RELEASE + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/java/com/baeldung/mongodb/SpringDataMongoDB.java b/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/java/com/baeldung/mongodb/SpringDataMongoDB.java new file mode 100644 index 0000000000..a38eddb0e8 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/java/com/baeldung/mongodb/SpringDataMongoDB.java @@ -0,0 +1,15 @@ +package com.baeldung.mongodb; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; +import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; + +@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) +public class SpringDataMongoDB { + + public static void main(String[] args) { + SpringApplication.run(SpringMongoDB.class, args); + } +} diff --git a/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/application.properties b/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/application.properties new file mode 100644 index 0000000000..9f190ed8ae --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/logback.xml b/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-mongodb/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-mongodb/src/test/java/com/baeldung/mongodb/SpringDataMongoDBIntegrationTest.java b/spring-data-disable-auto-configuration/spring-data-mongodb/src/test/java/com/baeldung/mongodb/SpringDataMongoDBIntegrationTest.java new file mode 100644 index 0000000000..33f5620c32 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-mongodb/src/test/java/com/baeldung/mongodb/SpringDataMongoDBIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.mongodb; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringMongoDB.class) +public class SpringDataMongoDBIntegrationTest { + + @Autowired + private ApplicationContext context; + + @Test(expected = NoSuchBeanDefinitionException.class) + public void givenAutoconfigurationIsDisable_whenApplicationStarts_thenContextWillNotHaveTheAutoconfiguredClasses() { + context.getBean(MongoTemplate.class); + } + +} diff --git a/spring-data-disable-auto-configuration/spring-data-redis/README.md b/spring-data-disable-auto-configuration/spring-data-redis/README.md new file mode 100644 index 0000000000..b91f5eda5a --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-redis/README.md @@ -0,0 +1,4 @@ +This module is for Jira BAEL-2578 + + +### Relevant Articles: diff --git a/spring-data-disable-auto-configuration/spring-data-redis/pom.xml b/spring-data-disable-auto-configuration/spring-data-redis/pom.xml new file mode 100644 index 0000000000..7c997033ed --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-redis/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + com.baeldung + spring-data-redis + 0.0.1-SNAPSHOT + spring-data-redis + jar + Spring Data with Redis + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-redis + 2.1.6.RELEASE + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-redis/src/main/java/com/baeldung/redis/SpringDataRedis.java b/spring-data-disable-auto-configuration/spring-data-redis/src/main/java/com/baeldung/redis/SpringDataRedis.java new file mode 100644 index 0000000000..d5a682834b --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-redis/src/main/java/com/baeldung/redis/SpringDataRedis.java @@ -0,0 +1,14 @@ +package com.baeldung.redis; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; +import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration; + +@SpringBootApplication(exclude = {RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class}) +public class SpringDataRedis { + + public static void main(String[] args) { + SpringApplication.run(SpringRedis.class, args); + } +} diff --git a/spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/application.properties b/spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/application.properties new file mode 100644 index 0000000000..8c5a8dbbfd --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration, org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/logback.xml b/spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-redis/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-data-disable-auto-configuration/spring-data-redis/src/test/java/com/baeldung/redis/SpringDataRedisIntegrationTest.java b/spring-data-disable-auto-configuration/spring-data-redis/src/test/java/com/baeldung/redis/SpringDataRedisIntegrationTest.java new file mode 100644 index 0000000000..e142713417 --- /dev/null +++ b/spring-data-disable-auto-configuration/spring-data-redis/src/test/java/com/baeldung/redis/SpringDataRedisIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.redis; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringRedis.class) +public class SpringDataRedisIntegrationTest { + + @Autowired + private ApplicationContext context; + + @Test(expected = NoSuchBeanDefinitionException.class) + public void givenAutoconfigurationIsDisable_whenApplicationStarts_thenContextWillNotHaveTheAutoconfiguredClasses() { + context.getBean(RedisTemplate.class); + } + +}