Voici mes fichiers et classes de configuration de printemps: -Autowiring à ressort ne fonctionnant pas avec les proxies
Je ne suis pas capable d'autowire la classe mandatée dans le service de test. Après avoir exécuté Test.java, j'obtiens NullPointerException, la propriété 'arthmeticCalculator' n'est pas définie.
Je ne comprends pas ce qui ne va pas? S'il vous plaît aidez-moi à résoudre ce problème.
<bean id="arthmeticCalculator" class="com.manoj.aop.test.CalculatorImpl"/>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Calculator</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>methodNameAdvisor</value>
</list>
</property>
</bean>
<bean id="methodNameAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
<property name="mappedNames">
<list>
<value>add</value>
<value>sub</value>
</list>
</property>
<property name="advice" ref="loggingAroundAdvice" />
</bean>
<bean id="loggingAroundAdvice" class="com.manoj.aop.test.LoggingAroundAdvice"/>
<bean id="testService" class="com.manoj.aop.test.TestService">
</bean>
Calculator.java:-
public interface Calculator {
public double add(double a,double b);
}
CacculatorImpl: -
public class CalculatorImpl implements Calculator {
public double add(double a, double b) {
return a+b;
}
}
LoggingAroundAdvice: -
public class LoggingAroundAdvice implements MethodInterceptor{
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
System.out.println("Around Invoice called");
Object result = methodInvocation.proceed();
return result;
}
}
TestService: -
public class TestService {
@Autowired
private Calculator arthmeticCalculator;
public void test(){
System.out.println(arthmeticCalculator.add(5, 10.5));
}
}
Test.java:-
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("com/manoj/aop/test/aop.xml");
TestService service = (TestService) context.getBean("testService");
service.test();
}
}
merci vous avez raison j'ai oublié annotation-config. Il fonctionne maintenant – Manoj