我有一个配置,它是@Import
由注释编辑的。我希望配置可以访问注释上的值。这可能吗?
配置:
@Configuration
public class MyConfig
{
@Bean
public CacheManager cacheManager(net.sf.ehcache.CacheManager cacheManager)
{
//Get the values in here
return new EhCacheCacheManager(cacheManager);
}
@Bean
public EhCacheManagerFactoryBean ehcache() {
EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
ehCacheManagerFactoryBean.setShared(true);
return ehCacheManagerFactoryBean;
}
}
注释
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Import(MyConfig.class)
public @interface EnableMyCaches
{
String value() default "";
String cacheName() default "my-cache";
}
如何在我的配置中获得下面传递的值?
@SpringBootApplication
@EnableMyCaches(cacheName = "the-cache")
public class MyServiceApplication {
public static void main(String[] args) {
SpringApplication.run(MyServiceApplication.class, args);
}
}