Как вы уже знаете, по умолчанию классы kotlin не могут быть расширены. Для поддержки наследования необходимо добавить ключевое слово open
. Кроме того, мы знаем, что для обработки весенних аннотаций нужны классы, помеченные как @Configuration
, которые могут быть разделены на подклассы.
Альтернатива написания открытого в каждом из классов - добавить плагин: kotlin-allopen
ex:
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
Приведенное выше описание позволяет добавить следующие примечания: @Component
, @Async
, @Transactional
, @Cacheable
и @SpringBootTest
. Благодаря поддержке метааннотаций классы, помеченные @Configuration
, @Controller
, @RestController
, @Service
или @Repository
, открываются автоматически, поскольку эти аннотации мета-аннотируются с помощью @Component
.
Youможете найти документацию здесь: https://kotlinlang.org/docs/reference/compiler-plugins.html