I need some help with creating Aspect bean.
I have module A
, B
... and module starter-x
.
I have a couple of Aspects declared in module starter-x, and configurations for them(like spring data repository monitoring aspect with configuration annotated with @ConditionalOnClass(Repository.class)
etc).
Here's how example configuration looks like
@Configuration
@ConditionalOnClass(Repository.class)
public class RepositoryMonitoringConfiguration {
@Bean
@Qualifier("RepositoryCallCounter")
public DatabaseCallCounter repositoryCounter(){
return new RepositoryCallCounter();
}
}
And i have class with @Aspect
annotation(but not @Component
, when i create bean with @Component
not @Configuration
, everything is ok)
So my question, is it possible to provide aspect bean in @Configuration
class, without @Component
annotation on it (I want to create cool starter with auto configuration)
It's possible, you just need to mark the configuration class like this:
@Configuration
@EnableAspectJAutoProxy
@ConditionalOnClass(Repository.class)
public class RepositoryMonitoringConfiguration {
@Bean
public DatabaseCallCounter repositoryCounter(){
return new RepositoryCallCounter();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With