前两天在学习Spring的切面编程,利用@EnableAspectJAutoProxy标签开启切面。却始终得不到想要的结果。不多说,直接上demo代码。
spring配置类
package com.xwh.cofig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import com.xwh.Interface.CompactDisc;
import com.xwh.aspect.EncoreableIntroducer;
import com.xwh.aspect.PlayerAspect;
import com.xwh.bean.CDPlayer;
import com.xwh.bean.MyBean;
import com.xwh.bean.StgPepper;
@Configuration
@EnableAspectJAutoProxy //启动切面代理
public class MainConfig {
@Bean(name="cdPlayer")
public CDPlayer cdPlayer(CompactDisc disc) {
return new CDPlayer(disc);
}
@Autowired
private Environment environment;
@Bean
public MyBean myBean(){
MyBean bean=new MyBean();
bean.setMessage(environment.getProperty("user.language"));
return bean;
}
@Bean
public CompactDisc stgPepper() {
return new StgPepper();
}
@Bean
public PlayerAspect playerAspect(){
return new PlayerAspect();
}
@Bean
public EncoreableIntroducer encoreableIntroducer(){
return new EncoreableIntroducer();
}
}
接口CompactDisc
package com.xwh.Interface;
public interface CompactDisc {