【发布时间】:2018-02-22 17:10:30
【问题描述】:
我有一个使用 Struts 1 制作的应用程序,它需要一些听觉,所以我想要使用方面,所以我不需要更改类,而是“拦截”对方法的调用。
我正在尝试使用 Spring AOP + Aspectj 集成,但首先我需要集成 Struts 和 Spring。我在这里尝试了几个教程和类似的问题,但显然它们主要用于 Struts 2。
更具体地说,我正在这样做:
web.xml
...
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
...
applicationContext.xml
<context:component-scan base-package="com.app"/>
<context:annotation-config/>
<aop:aspectj-autoproxy />
<bean id="loggerAspect" class="com.app.util.LoggerAspect"/>
LoggerAspect.java
@Aspect
public class LoggerAspect {
@Before("execution(* com.app.action.FileAction.list(..))")
public void test(JoinPoint joinPoint) {
System.out.println("Calling: " + joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName());
}
}
pom.xml
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<!-- -->
<!-- Spring AOP -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.13</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
我没有对 struts-config.xml 文件做任何事情。服务器加载应用程序没有任何问题,但 Spring 没有加载等方面。
知道如何解决这个问题吗?
【问题讨论】:
-
寻找答案我发现了这篇帖子stackoverflow.com/a/1606780/1950103,他们说:“Spring-AOP 无法向不是由 Spring 工厂创建的任何东西添加方面”。所以我的理解是我不能使用 Spring AOP 和 Struts,因为我没有将类映射为 bean。这是真的吗?
-
我已经在 applicationContext 中添加了我的类
com.app.action.FileAction作为 bean,但仍然无法加载 Spring
标签: java spring aspectj spring-aop struts-1