我有一个扩展PlainDataSource
的bean BeanNameAware
(在外部库中)。在其方法setBeanName
中,它记录了一条消息
Adding bean {} to container
我决定编写一个方面,可以执行与applicationContext
方法之后setBeanName
设置环境相关的一些操作。
@Component
@Aspect
public class DataSourceInitializerAspect {
@Autowired
private ApplicationContext applicationContext;
@After("execution (* com.path.to.package.PlainDataSource.setBeanName(..))")
public void initializeEnvironment() {
LOGGER.info("!!!!!!!!!!!!! Invoking aspect !!!!!!!!!!!!!!!!!");
CustomPropertiesConfigurerExt propertiesConfigurer =
applicationContext.getBean(CutsomPropertiesConfigurerExt.class);
boolean localConfig = Boolean.parseBoolean(propertiesConfigurer.resolveProperty("localConfig"));
ConfigurableEnvironment env = (ConfigurableEnvironment) applicationContext.getEnvironment();
if (localConfig) {
env.setActiveProfiles("local");
} else {
env.setActiveProfiles("server");
}
}
}
至context.xml
我添加了
<aop:aspectj-autoproxy/>
具有相应的命名空间
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
之前
<context:annotation-config/>
但是当我开始申请时,我收到了消息
"Adding bean datasource to container"
但是没有收到invoking aspect
消息,所以我假设没有调用任何方面。问题是什么?