Spring Boot *AutoConfiguration-classes exclusion management is actually a hell. Thanks to the spring-boot-autoconfigure module which is suited to be a global module for everything.
The issue that has motivated me to do such pull request is all the things that have been pulled up when I added spring-boot-starter-data-r2dbc and org.jooq:jooq dependencies. Adding these dependencies automatically triggers creation of ConnectionFactory, TransactionManager, repository support released beans, JOOQ' related DSL and Configuration beans creation. BUT I was needed only to have ConnectionFactory!.
I don't want to manage transactions through Spring. And I don't want Spring to create JOOQ related beans — I am going to manage them right in the business logic code using DSL.using(connectionFactory). ... API.
So I started to exclude these auto configurations manually.
My main method with @SpringAutoConfiguration annotation started to getting bigger on the almost fresh project. At another project it already has 15 exclusionName rules !
@SpringBootApplication(
excludeName = [
"org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration",
"org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration",
"org.springframework.boot.autoconfigure.r2dbc.R2dbcTransactionManagerAutoConfiguration",
"org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration",
]
)
class SpringAutoconfigurePracticeApplication
fun main(args: Array<String>) {
runApplication<SpringAutoconfigurePracticeApplication>(*args)
}
Comparing to Spring, Micronaut doesn't have such problem because configuration classes ship with features inside the same jar. Hence, if you don't need some configuration to apply or even to exist — just remove the jar from the classpath.
I suggest to allow glob patterns in excludeName parameter to make this block shorter:
@SpringBootApplication(
excludeName = [
"org.springframework.boot.autoconfigure.flyway", // valid because exact path
"org.springframework.boot.autoconfigure.r2dbc.*", // valid glob
"org.springframework.boot.autoconfigure.jooq.**", // valid glob
]
)
class SpringAutoconfigurePracticeApplication
fun main(args: Array<String>) {
runApplication<SpringAutoconfigurePracticeApplication>(*args)
}
See https://github.com/spring-projects/spring-boot/pull/33115
Comment From: wilkinsona
Unfortunately, describing something as "a hell" is neither constructive nor informative. It sounds like you may have more dependencies on your classpath than you need but you haven't taken the time to describe why you have a dependency on spring-boot-starter-data-r2dbc when, apparently, you don't want to use Spring Data.
Irrespective of how the auto-configuration is packaged, having unneeded dependencies on the classpath will cause things to be auto-configured that you do not need. If you want to use jOOQ with R2DBC and don't want Spring Data's R2DBC repositories, Spring Framework's transaction management, etc, depending on only jOOQ and R2DBC will get you much closer without having to exclude anything.
If only depending on the things that you need doesn't help, please take the time to describe why that's the case. It may be that the auto-configuration is insufficiently flexible. If so, I think it would be better that we fix that than add complexity to how auto-configuration can be excluded.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.