From e842b87ec53cc8e391de030e7b043c68e5168f68 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Thu, 21 Sep 2023 15:22:42 +0530 Subject: [PATCH] =?UTF-8?q?JAVA-23380:=20Changes=20made=20for=20upgrading?= =?UTF-8?q?=20sprint-boot-autoconfiguration=20=E2=80=A6=20(#14769)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring-boot-autoconfiguration/pom.xml | 14 +++++++++++--- .../autoconfiguration/MySQLAutoconfiguration.java | 7 ++++--- .../annotationprocessor/DatabaseProperties.java | 6 ++++-- .../baeldung/autoconfiguration/example/MyUser.java | 4 ++-- .../src/main/resources/META-INF/spring.factories | 1 - ...rk.boot.autoconfigure.AutoConfiguration.imports | 1 + .../src/main/resources/mysql.properties | 2 +- 7 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml index 7a3f9f01e8..7880a033f8 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml +++ b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml @@ -10,9 +10,10 @@ This is simple boot application demonstrating a custom auto-configuration - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -66,6 +67,13 @@ org.apache.maven.plugins maven-war-plugin + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.autoconfiguration.example.AutoconfigurationApplication + + diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java index 295e0d74c9..c470656597 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java @@ -3,10 +3,10 @@ package com.baeldung.autoconfiguration; import java.util.Arrays; import java.util.Properties; -import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; @@ -20,7 +20,6 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; @@ -31,7 +30,9 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.util.ClassUtils; -@Configuration +import jakarta.persistence.EntityManagerFactory; + +@AutoConfiguration @ConditionalOnClass(DataSource.class) @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) @PropertySource("classpath:mysql.properties") diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java index 4fb5b408a2..47f07c808f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java @@ -1,11 +1,13 @@ package com.baeldung.autoconfiguration.annotationprocessor; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; + @Configuration @ConfigurationProperties(prefix = "database") public class DatabaseProperties { diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java index 31ce0fd969..26a2e04e2f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java @@ -1,7 +1,7 @@ package com.baeldung.autoconfiguration.example; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class MyUser { diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories index 11c775fc6c..e69de29bb2 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories @@ -1 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baeldung.autoconfiguration.MySQLAutoconfiguration diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000..ab28361814 --- /dev/null +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.baeldung.autoconfiguration.MySQLAutoconfiguration diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties index 74f1ee1373..27092f852f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties @@ -1,5 +1,5 @@ usemysql=local -mysql-hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +mysql-hibernate.dialect=org.hibernate.dialect.MySQLDialect mysql-hibernate.show_sql=true mysql-hibernate.hbm2ddl.auto=create-drop \ No newline at end of file