I'm using Spring boot 2.3.1 and Kotlin 1.3.72. I've updated it several days ago. Since that moment I've had problem with dependency injection. I don't use @Service
, @Component
etc. annotations, I rather prefer creating beans by @Configuration
class, so for example I have this kind of configuration:
@Configuration
open class MatchModule {
@Bean
open fun matchFacade(
matchQueryService: MatchQueryService,
purchaseFacade: PurchaseFacade,
rankFacade: RankFacade,
timeService: TimeService
): MatchFacade {
return MatchFacade(
timeService = timeService,
matchQueryService = matchQueryService,
purchaseFacade = purchaseFacade,
rankFacade = rankFacade
)
}
@Bean
open fun matchQueryService(sparringViewRepository: SparringViewRepository, animalProfileMatchViewRepository: AnimalProfileMatchViewRepository): MatchQueryService {
return MatchQueryService(sparringViewRepository, animalProfileMatchViewRepository)
}
}
The MatchFacade
has a transactional method and inside it all dependencies are null
.
I know that I can make all facades and methods as open
because of CGLIB
proxy, but I have standard spring boot build config in pom.xml
:
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<compilerPlugins>
<plugin>jpa</plugin>
</compilerPlugins>
<jvmTarget>1.8</jvmTarget>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<!--...-->
</plugin>
</plugins>
</build>
Why it doesn't work wihout open class and methods ?