SpringMVC+;未调用AspectJ
您好,我阅读了之前关于我的问题的所有帖子,并应用了所有建议,但我还没有找到解决方案。SpringMVC+;未调用AspectJ,spring,aspectj,Spring,Aspectj,您好,我阅读了之前关于我的问题的所有帖子,并应用了所有建议,但我还没有找到解决方案。 在我的springMVC+AspectJ配置中,控制器工作正常,但没有执行切入点。 这里是我的配置和代码: -- /WEB-INF/web.xml --- <web-app> <display-name>MODULE-WEB</display-name> <context-param>
在我的springMVC+AspectJ配置中,控制器工作正常,但没有执行切入点。 这里是我的配置和代码:
-- /WEB-INF/web.xml ---
<web-app>
<display-name>MODULE-WEB</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
...
**
带注释的方法是受保护的,但它应该是公共的 说: 由于Spring的AOP框架基于代理的特性,受保护的方法根据定义是不被拦截的,既不适用于JDK代理(如果这不适用),也不适用于CGLIB代理(如果这在技术上是可能的,但不推荐用于AOP目的)。因此,任何给定的切入点将只与公共方法匹配
如果要匹配
受保护
或私有
方法,请通过LTW使用AspectJ。我猜您还有一个DispatcherServlet
正在加载控制器类。方面(通常是AOP)将只应用于相同上下文中的bean。huawuuuu!!!!这就是问题所在!!!!控制器上的方法必须是公共的。很多thnks的家伙!!!
-- /WEB-INF/ApplicationContext.xml -----
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"
>
<mvc:annotation-driven/>
<context:annotation-config/>
<context:component-scan base-package="it.max.test"/>
<!-- AOP -->
<aop:aspectj-autoproxy/>
<!-- EJB -->
<bean id="testService" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
<property name="jndiName" value="java:app/MODULE-EJB/TestService"/>
<property name="businessInterface" value="it.max.test.services.ITestService"/>
</bean>
</beans>
-- Monitor.java ---
package it.max.test.security;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.stereotype.Component;
@Component
@Target(value={ElementType.METHOD, ElementType.TYPE})
@Retention(value=RetentionPolicy.RUNTIME)
public @interface Monitor {
}
-- AuthorizationInterceptor.java --
package it.max.test.security;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.CodeSignature;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class AuthorizationInterceptor {
@Before(value="@within(it.max.test.security.Monitor) || @annotation(it.max.test.security.Monitor)")
public void before(JoinPoint jp){
Object[] paramValues=jp.getArgs();
String[] paramNames=((CodeSignature)jp.getStaticPart().getSignature()).getParameterNames();
for(int i=0;i<paramValues.length;i++){
System.out.println("["+paramNames[i]+"]:["+paramValues[i]+"]");
}
}
}
--TestController.java---
package it.max.test.controllers;
import it.max.test.security.Monitor;
import it.max.test.services.ITestService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class TestController {
@Autowired
private ITestService testService;
@Monitor
@RequestMapping("/test.view")
protected ModelAndView test(HttpServletRequest arg0,HttpServletResponse arg1) throws Exception {
ModelAndView mv=new ModelAndView();
testService.test("AAA");
mv.setViewName("test");
return mv;
}
}