Ana fasülye fabrikam var ve fasülyede fasülye fasülyesi işlemek için BeanPost Processor'u tercih ediyorum. AFAIK, bu Baharda desteklenmiyor. Benim alternatiflerim neler? (her işlemin XML'sinde post işlemcisini bildirmek için tabii ki hariç)Ana fasulyesi fabrikalarında fasülye fabrikasında fasülye işlemcileri almak için
5
A
cevap
0
Bir "çözüm", üst yazı işleyicilerini yürüten alt bağlama için bir fasulye son işlemci eklenmesidir. Bu, kullandığımız tekniktir. Potansiyel olarak tehlikeli ve en iyi Bahar pratiği IMO değil.
/**
* A {@linkplain BeanPostProcessor} that references the BeanPostProcessors in the parent context and applies them
* to context this post processor is a part of. Any BeanPostProcessors from the parent that are {@link BeanFactoryAware} will
* have the {@linkplain BeanFactory} from the child context set on them during the post processing. This is necessary to let such post processors
* have access to the entire context.
*/
public class ParentContextBeanPostProcessor implements BeanPostProcessor {
private final Collection<BeanPostProcessor> parentProcessors;
private final BeanFactory beanFactory;
private final BeanFactory parentBeanFactory;
/**
* @param parent the parent context
* @param beanFactory the beanFactory associated with this post processor's context
*/
public ParentContextBeanPostProcessor(ConfigurableApplicationContext parent, BeanFactory beanFactory) {
this.parentProcessors = parent.getBeansOfType(BeanPostProcessor.class).values();
this.beanFactory = beanFactory;
this.parentBeanFactory = parent.getBeanFactory();
}
/** {@inheritDoc} */
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
for (BeanPostProcessor processor : parentProcessors) {
if (processor instanceof BeanFactoryAware) {
((BeanFactoryAware) processor).setBeanFactory(beanFactory);
}
try {
bean = processor.postProcessBeforeInitialization(bean, beanName);
} finally {
if (processor instanceof BeanFactoryAware) {
((BeanFactoryAware) processor).setBeanFactory(parentBeanFactory);
}
}
}
return bean;
}
/** {@inheritDoc} */
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
for (BeanPostProcessor processor : parentProcessors) {
if (processor instanceof BeanFactoryAware) {
((BeanFactoryAware) processor).setBeanFactory(beanFactory);
}
try {
bean = processor.postProcessAfterInitialization(bean, beanName);
} finally {
if (processor instanceof BeanFactoryAware) {
((BeanFactoryAware) processor).setBeanFactory(parentBeanFactory);
}
}
}
return bean;
}
}
Ebeveyn-çocuk bağlamlarında daha fazla koruma kullanımı dışında, farkında olduğum başka alternatifler yoktur. – skaffman