私は単純なアスペクトをテストしようとしています。 アプリはコンパイルされて正常に動作しますが、Aspectは実行されません。あるいは、少なくとも、アスペクトが生成すべき出力を得ることはできません。 (私の目的は、アプリ内で発生したすべての例外のロガーを書くことですが、最初にこのテストのアスペクトを実行する必要があります...)アスペクトが実行されない
多面的な経験を持っている人は、
package business;
public interface Customer {
void addCustomer();
}
import org.springframework.stereotype.Component;
@Component
public class CustomerImpl implements Customer {
public void addCustomer() {
System.out.println("addCustomer() is running ");
}
}
@RequestScoped @Named
//this is backing bean for jsf page
public class Service {
@Inject
Customer cust;
add() {
System.out.println("Service is running ");
cust.addCustomer();
}
}
@Aspect
public class AspectComp {
@Before("within(business..*)")
public void out() {
System.out.println("system out works!!");
}
}
春:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
<context:annotation-config />
<context:component-scan base-package="business" />
<aop:aspectj-autoproxy />
</beans>
出力:
Service is running
addCustomer() is running
アスペクトの文が欠落しています。
Springの設定はどのようになっていますか? –
上記の更新は、うまくいけば重要な情報を削除しました。私が春の設定で変更した唯一の設定は、* .xsdと です。 –
membersound
コンポーネントをコンストラクタで作成していて、Springコンテナから取得していません!それが問題です。 –