如何为 jax-rs 编写 spring AOP
How to write spring AOP for jax-rs
我是 spring AOP 的初学者。我的要求是在 invokeTestServer 方法之前登录 execution.Please 在下面找到我的代码:
应用-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>
在尝试将 AOP 与 jax-rs 集成时,我没有任何要初始化的特定 bean
请在下面找到我的组件
package mypackage.service;
@Component
public class FirstProcess {
public Response invokeTestServer() throws TestServerException{
//Logic
return response;
}
}
我的长相如下
包裹 mypackage.spring;
@看点
public class InputAcceptorAspect {
@Before("execution(*mypackage.service.invokeTestServer(..))")
public void logBeforeInvokingTestServer(JoinPoint joinpoint){
logger.error("TestServer got invoked");
System.out.println("TestServer got invoked");
}
}
我正在尝试使用以下主要内容进行测试 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();
}
}
在执行上述操作时出现异常,无法创建文件中定义的 bean FirstProcess..
如有任何帮助,我们将不胜感激。
在 class FirstProcess.java 中,您正在尝试创建带有注释的 bean,但注释配置不存在于配置中。在 application-context.xml 文件中添加此标记以使用注释配置
创建 bean
我是 spring AOP 的初学者。我的要求是在 invokeTestServer 方法之前登录 execution.Please 在下面找到我的代码:
应用-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>
在尝试将 AOP 与 jax-rs 集成时,我没有任何要初始化的特定 bean
请在下面找到我的组件
package mypackage.service;
@Component
public class FirstProcess {
public Response invokeTestServer() throws TestServerException{
//Logic
return response;
}
}
我的长相如下 包裹 mypackage.spring;
@看点
public class InputAcceptorAspect {
@Before("execution(*mypackage.service.invokeTestServer(..))")
public void logBeforeInvokingTestServer(JoinPoint joinpoint){
logger.error("TestServer got invoked");
System.out.println("TestServer got invoked");
}
}
我正在尝试使用以下主要内容进行测试 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();
}
}
在执行上述操作时出现异常,无法创建文件中定义的 bean FirstProcess..
如有任何帮助,我们将不胜感激。
在 class FirstProcess.java 中,您正在尝试创建带有注释的 bean,但注释配置不存在于配置中。在 application-context.xml 文件中添加此标记以使用注释配置
创建 bean