ben şöyle "AutowireCapableBeanFactory" kullanarak dinamik fasulye oluşturma içinde bir yöntem için önbelleği etkinleştirmedinamik fasulye
RegisterFoo.java
@Configuration
public class registerFoo {
@Autowired
ApplicationContext appcontext;
AutowireCapableBeanFactory bf;
@PostConstruct
public void registerFoo() {
bf = appContext.getAutowireCapableBeanFactory();
RootBeanDefinition def = new RootBeanDefinition(Foo.class);
((DefaultListableBeanFactory)bf).registerBean("foo", def);
}
}
RegisterBar.java
@Configuration
public class registerBar {
@Autowired
ApplicationContext appcontext;
AutowireCapableBeanFactory bf;
@PostConstruct
public void registerFoo() {
bf = appContext.getAutowireCapableBeanFactory();
RootBeanDefinition def = new RootBeanDefinition(Bar.class);
Foo foo = (Foo) appContext.getBean("foo");
ConstructorArgumentValues cav = new ConstructorArgumentValues();
cav.add(0, foo.getValue());
def.setArgumentValues(cav);
((DefaultListableBeanFactory)bf).registerBean("bar", def);
}
}
Foo.class
public class Foo {
@Cacheable
public String getValue() {
// return value
}
}
GetValue() yöntemi, her defasında vücudunu yürütür. Bahar, değeri beklendiği gibi önbelleğe almaz. Baska öneri?
Burada herhangi bir girdi gerçekten takdir edildi. – sag
Uygulamanızda önbelleğin çalıştığı başka yerler var mı? Dinamik fasülyenin dışında mı? – Patrick
@Patrick - Evet, normal fasulyeler için çalışıyor. yani fasulye, '' '@ Bean'' kullanılarak eklenmiştir. – sag