
Originally Posted by
Marten Deinum
Aspects are only applied in the ApplicationContext they are defined in. Yours is defined in the root application context (loaded by the ContextLoaderListener) and your controller is probably loaded by the one loaded from the DispatcherServlet. The parent applicationcontext doesn't know about it's childs contexts.
Hi Marten,
I have the same problem as bqiao, but I put the aspect in the same context of my controllers.
My aspect is as follow:
Code:
package it.esel.ge.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class ValidUserSessionAdvice {
@Pointcut("execution(* *..handleRequest(..))")
public void inControllers() {}
@Around("inControllers()")
public Object doValidation(ProceedingJoinPoint pjp) throws Throwable {
Object[] arguments = pjp.getArgs();
System.out.println(arguments[0].getClass().getName());
return pjp.proceed(arguments);
}
}
My controllers and the aspect are defined in <webapp name>-servlet.xml:
Code:
<!--
- DispatcherServlet application context for the Spring web MVC
- implementation of AnagrafeWeb's web tier.
-->
<beans>
<!-- ========================= VIEW DEFINITIONS ========================= -->
<bean id="viewResolver1" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
...
<bean name="/ricerca.do" class="it.esel.ge.controllers.RicercaController">
<property name="tableJoinsService" ref="tableJoins" />
</bean>
...
<bean id="validUserSessionAdvice" class="it.esel.ge.aop.ValidUserSessionAdvice" />
<beans>
The aspectj-autoproxy it's enabled into the ApplicationContext (<aop:aspectj-autoproxy />).
The above controller is as follow:
Code:
package it.esel.ge.controllers;
...
import it.esel.ge.controllers.base.AWController;
...
public class RicercaController extends AWController implements IController {
private final static String QUERY_INFO_MESSAGE = "Query ricerca dati: ";
...
private IJoinsService tableJoinsService;
/**
* @author Riccardo Forafò
* @since Mar 7, 2008
*
* @param tableJoinsService
*/
public void setTableJoinsService(IJoinsService tableJoinsService) {
this.tableJoinsService = tableJoinsService;
}
/*
* Riccardo Forafò
* Mar 7, 2008
*
* (non-Javadoc)
* @see it.esel.ge.controllers.base.AWController#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<Object, Object> model = new HashMap<Object, Object>();
ModelAndView modelAndView = null;
...
and it's extend a base controller that implemets the Controller interface:
Code:
package it.esel.ge.controllers.base;
import org.springframework.web.servlet.mvc.Controller;
...
public class AWController extends ApplicationObjectSupport implements Controller {
protected static ReloadableResourceBundleMessageSource propertiesRepository;
protected static MessageSource staticPropertiesRepository;
...
public AWController() {
super();
}
...
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
return null;
}
...
I'm not able to understand what I'm doing wrong.
Could you help me please?
Thank you.
Riccardo.