Skip to content

Commit

Permalink
Switch from spring.factories to AutoConfiguration.imports (JetBrains#…
Browse files Browse the repository at this point in the history
…1636) (JetBrains#1645)

Co-authored-by: Ronny Bräunlich <ronny.braeunlich@cbc.de>
  • Loading branch information
2 people authored and saral committed Oct 3, 2023
1 parent e0cb60c commit b39adcd
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ object Versions {
const val sqlserver = "9.4.1.jre8"

/** Spring **/
const val springFramework = "5.3.29"
const val springBoot = "2.7.14"
const val springFramework = "6.0.11"
const val springBoot = "3.1.3"
}
19 changes: 15 additions & 4 deletions exposed-spring-boot-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions exposed-spring-boot-starter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

kotlin {
jvmToolchain(8)
jvmToolchain(17)
}

dependencies {
Expand All @@ -25,7 +25,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<Test>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ 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.AutoConfigureAfter
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
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) {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.jetbrains.exposed.spring.autoconfigure.ExposedAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -53,6 +58,18 @@ open class ExposedAutoConfigurationTest {
)
}

@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 {

Expand Down
2 changes: 1 addition & 1 deletion spring-transaction/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

kotlin {
jvmToolchain(8)
jvmToolchain(17)
}

dependencies {
Expand Down

0 comments on commit b39adcd

Please sign in to comment.