正常结果
当加入aop后
@Component
@Aspect
public class myAdvice {
@Pointcut("execution(* *(..))")
public void pt(){}
@Before("pt()")
public void advice(){
System.out.println(System.currentTimeMillis());
}
}
druid的数据源全部变为空,没有设置成功
修改切面为部分方法后又可以成功读取不知道为什么?
继续找问题,缩小aop切面,发现问题出现在jdbcConfig类中
@Bean
private DataSource dataSource(){
System.out.println(username);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
如果给这个方法加上aop就会报错,如果在
@Pointcut("execution(* com.hang.config.jdbcConfig.dataSource())")写完整方法名,会标位红色提示Cannot resolve symbol 'dataSource'
终于找到问题所在了,我将datasource注册为bean的时候设置为了私有方法,无法访问,修改为public后程序可以正常运行.