diff --git a/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/Versions.kt b/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/Versions.kt index 24b09e7739..23722905f0 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/Versions.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/Versions.kt @@ -22,8 +22,8 @@ object Versions { const val sqlserver = "9.4.1.jre8" /** Spring **/ - const val springFramework = "5.3.22" - const val springBoot = "2.7.2" + const val springFramework = "6.0.11" + const val springBoot = "3.1.3" /** Test Dependencies **/ const val testContainers = "1.17.3" diff --git a/exposed-spring-boot-starter/README.md b/exposed-spring-boot-starter/README.md index 68488911f0..9cedde4893 100644 --- a/exposed-spring-boot-starter/README.md +++ b/exposed-spring-boot-starter/README.md @@ -50,13 +50,24 @@ Example: ```kotlin @Configuration +@EnableAutoConfiguration(exclude = [DataSourceTransactionManagerAutoConfiguration::class]) class ExposedConfig { - @Bean - fun databaseConfig() = DatabaseConfig { - useNestedTransactions = true - } + @Bean + fun databaseConfig() = DatabaseConfig { + useNestedTransactions = true + } } ``` +It is recommended that the `DataSourceTransactionManagerAutoConfiguration` class be excluded from auto-configuration, which can be done in a custom configuration, as shown above. + +Alternatively, the class can be disabled using the `exclude` attribute of `@SpringBootApplication`: + +```kotlin +@SpringBootApplication(exclude = [DataSourceTransactionManagerAutoConfiguration::class]) +class MyApplication +``` + +See the [official documentation](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.auto-configuration.disabling-specific) for more options to exclude auto-configuration classes. ## Automatic Schema Creation This starter will create the database schema if enabled automatically using any class that extends `org.jetbrains.exposed.sql.Table` diff --git a/exposed-spring-boot-starter/build.gradle.kts b/exposed-spring-boot-starter/build.gradle.kts index 988b94a8b1..a6eb2e1e31 100644 --- a/exposed-spring-boot-starter/build.gradle.kts +++ b/exposed-spring-boot-starter/build.gradle.kts @@ -21,7 +21,7 @@ dependencies { testImplementation("org.springframework.boot", "spring-boot-starter-test", Versions.springBoot) // put in testImplementation so no hard dependency for those using the starter testImplementation("org.springframework.boot", "spring-boot-starter-webflux", Versions.springBoot) - testImplementation("com.h2database", "h2", Versions.h2) + testImplementation("com.h2database", "h2", Versions.h2_v2) } tasks.withType().configureEach { diff --git a/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfiguration.kt b/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfiguration.kt index 9f6a946d85..b3d0f195a7 100644 --- a/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfiguration.kt +++ b/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfiguration.kt @@ -4,6 +4,7 @@ import org.jetbrains.exposed.spring.DatabaseInitializer import org.jetbrains.exposed.spring.SpringTransactionManager import org.jetbrains.exposed.sql.DatabaseConfig import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.autoconfigure.AutoConfiguration import org.springframework.boot.autoconfigure.AutoConfigureAfter import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty @@ -14,8 +15,7 @@ import org.springframework.context.annotation.Configuration import org.springframework.transaction.annotation.EnableTransactionManagement import javax.sql.DataSource -@Configuration -@AutoConfigureAfter(DataSourceAutoConfiguration::class) +@AutoConfiguration(after = [DataSourceAutoConfiguration::class]) @EnableTransactionManagement open class ExposedAutoConfiguration(private val applicationContext: ApplicationContext) { diff --git a/exposed-spring-boot-starter/src/main/resources/META-INF/spring.factories b/exposed-spring-boot-starter/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 94646e77db..0000000000 --- a/exposed-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,4 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - org.jetbrains.exposed.spring.autoconfigure.ExposedAutoConfiguration -org.springframework.boot.autoconfigure.EnableAutoConfiguration.exclude=\ - org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration \ No newline at end of file diff --git a/exposed-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/exposed-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000..38704b9d7c --- /dev/null +++ b/exposed-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.jetbrains.exposed.spring.autoconfigure.ExposedAutoConfiguration diff --git a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/Application.kt b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/Application.kt index 1161841bbb..24016d810f 100644 --- a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/Application.kt +++ b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/Application.kt @@ -2,10 +2,11 @@ package org.jetbrains.exposed.spring import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration import org.springframework.scheduling.annotation.EnableAsync @EnableAsync -@SpringBootApplication +@SpringBootApplication(exclude = [DataSourceTransactionManagerAutoConfiguration::class]) open class Application { open fun main(args: Array) { diff --git a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt index d81a0b0777..0d691ece9e 100644 --- a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt +++ b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt @@ -1,5 +1,6 @@ package org.jetbrains.exposed.spring.autoconfigure +import org.jetbrains.exposed.spring.Application import org.jetbrains.exposed.spring.DatabaseInitializer import org.jetbrains.exposed.spring.SpringTransactionManager import org.jetbrains.exposed.spring.tables.TestTable @@ -9,9 +10,13 @@ import org.jetbrains.exposed.sql.selectAll import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test +import org.springframework.beans.factory.NoSuchBeanDefinitionException import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.AutoConfigurations +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.TestConfiguration +import org.springframework.boot.test.context.runner.ApplicationContextRunner import org.springframework.context.annotation.Bean import org.springframework.scheduling.annotation.Async import org.springframework.stereotype.Service @@ -50,6 +55,18 @@ open class ExposedAutoConfigurationTest { assertEquals(expectedConfig.maxEntitiesToStoreInCachePerEntity, databaseConfig!!.maxEntitiesToStoreInCachePerEntity) } + @Test + fun testClassExcludedFromAutoConfig() { + val contextRunner = ApplicationContextRunner().withConfiguration( + AutoConfigurations.of(Application::class.java) + ) + contextRunner.run { context -> + assertThrows(NoSuchBeanDefinitionException::class.java) { + context.getBean(DataSourceTransactionManagerAutoConfiguration::class.java) + } + } + } + @TestConfiguration open class CustomDatabaseConfigConfiguration {