I am beginner in spring AOP. My requirement is to log before invokeTestServer method execution.Please find my code below:
application-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<aop:aspectj-autoproxy expose-proxy="true" />
<context:component-scan base-package="mypackage.service" />
<bean id="loggingAspect" class="mypackage.spring.InputAcceptorAspect" />
</beans>
As am trying to integrate AOP with jax-rs i dont have any specific bean to be initialized
please find below my component
package mypackage.service;
@Component
public class FirstProcess {
public Response invokeTestServer() throws TestServerException{
//Logic
return response;
}
}
My Aspect is as below package mypackage.spring;
@Aspect
public class InputAcceptorAspect {
@Before("execution(*mypackage.service.invokeTestServer(..))")
public void logBeforeInvokingTestServer(JoinPoint joinpoint){
logger.error("TestServer got invoked");
System.out.println("TestServer got invoked");
}
}
And am trying to test with below main class
package mypackage.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import mypackage.service.FirstProcess;
public class TestAOP {
public static void main(String args[])
{
ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
FirstProcess manager = context.getBean(FirstProcess.class);
manager.invokeTestServer();
}
}
While executing the above am getting an exception failed to create bean FirstProcess defined in file..
Any help would be appreciated.