것은 나에게 처음 foremention하자, 내가 직면하고있어 문제는 내가 작업에 봄에서 자습서를 실행 해요이 Spring Aspect가 메소드 매개 변수와 같이 인쇄되지 않는 이유는 무엇입니까?
를 인쇄하지 첫 번째 코드 블록에서의 interceptThoughts(String thoughts)
방법입니다. 가로 세로가 Volunteer
implements Thinker
해당 인터페이스의 마음을 읽을 생각하는 Magician
클래스 그 implements MindReader
방법 interceptThoughts(String thoughts)
와 인터페이스와 getThoughts()
@Aspect
public class Magician implements MindReader {
private String thoughts;
@Pointcut("execution(* com.underdogdevs.myspringaspectj."
+ "Thinker.thinkOfSomething(String)) && args(thoughts)")
public void thinking(String thoughts) {
}
@Override
@Before("thinking(thoughts)")
public void interceptThoughts(String thoughts) {
System.out.println("Intercepting volunteer's thoughts : " + thoughts);
this.thoughts = thoughts;
}
@Override
public String getThoughts() {
return thoughts;
}
}
는 방법 나는 내 자바 BeanConfig
이 thinkOfSomething(String thoughts)
public class Volunteer implements Thinker {
private String thoughts;
@Override
public void thinkOfSomething(String thoughts) {
this.thoughts = thoughts;
System.out.println("Something");
}
public String getThoughts() {
return thoughts;
}
}
함께있다 Magician
및 Volunteer
@Configuration
public class BeanConfig {
@Bean
public MindReader magician() {
return new Magician();
}
@Bean
public Thinker volunteer() {
return new Volunteer();
}
}
그리고
public class App {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("spring-idol.xml");
System.out.println();
Thinker volunteer = (Thinker)context.getBean("volunteer");
volunteer.thinkOfSomething("This is what I'm thinking");
}
}
- NO Eorrrs
- 예외
- 패키지
interceptThoughts
방법에 선을 인쇄하지하는Magician
방법을 얻기 위해 그것을 실행하기 위해 노력하고있어Magician
부분의@Pointcut(execution(
에서 올바른 것입니다. 나는 문제는 예상대로 인쇄되지 않는
Magician
측면에서@Before
나의 봄 구성 XML<context:component-scan base-package="com.underdogdevs.myspringaspectj" /> <aop:aspectj-autoproxy />
이 두 항목이있다. 여기에 뭔가가 빠졌습니까? 인쇄되지 않는 이유는 무엇입니까? 나는 인수를 취하지 않고 잘 실행하는 다른 aspect 메소드를 가지고있다. 매개 변수 값을 올바르게 전달하지 않습니까?
이 야생 추측 할 수있다; Volunteer와 Magician에게'@ Component's로 주석을 달았습니까? 또는 @Before 주석 안에 pointcut을 두는 것입니까? –
! guido 방금 시도했지만 작동하지 않습니다. 은 컨텍스트 내에서 bean을 스캔하기 위해서'@ Component'를 정확하게 지정하지 않고있는 것입니다. –
실제로'context : component-scan'은 * @Component 주석 (@Service, @Controller, 또한 @Component로 메타 주석이 첨부 된 @Configuration)을 검색 할 때 클래스 *를 검색하십시오. –