Hello - I'm hoping someone can spot something wrong with my configuration. I'm trying to execute an aspect on a class that is a Servlet. I've created the following implementation and have made the servlet a Spring Managed bean that is injected into a ServletDelegationController class. I am expecting that when the "doGet" method of the servlet is called, the aspect should execute. Unfortunately, that isn't the case. I took it a step further and created a SimpleBean that is injected into the servlet and added a pointcut expression for the call to the "logSomething" method. This method call DOES execute the aspect.
Please see the various configuration files and the SimpleAroundAspect class below for the details of my config. (Note: I've also verfied that the package, class and method names are correct)
Thanks in advance.
web.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>ABCNet 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> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <servlet> <servlet-name>DispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>DispatcherServlet</servlet-name> <url-pattern>/asset</url-pattern> </servlet-mapping> </web-app>
applicationContext.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans> <context:property-placeholder/> <import resource="intranet-MonitoringSpringAspects.xml" /> <bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetClass" value="org.springframework.util.Log4jConfigurer" /> <property name="targetMethod" value="initLogging" /> <property name="arguments"> <list> <value>classpath:log4j.dev.xml</value> </list> </property> </bean> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/asset">assetServletDelegationController</prop> </props> </property> </bean> <bean id="assetServletDelegationController" class="com.abc.intranet.web.servlet.ServletDelegationController"> <property name="servlet" ref="assetServletBean"/> <property name="servletName"> <value>AssetServlet</value> </property> <property name="initParameters"> <props> <prop key="folderFilter">/intranet/resources</prop> </props> </property> </bean> <bean id="assetServletBean" class="com.abc.intranet.web.servlet.IntraAssetServlet"> <property name="simpleBean" ref="aSimpleBean"/> </bean> <bean id="aSimpleBean" class="com.abc.intranet.web.servlet.SimpleBean"/> <context:annotation-config/> </beans>
intranet-MonitoringSpringAspects.xmlSimpleAroundAspect classCode:<?xml version="1.0" encoding="UTF-8"?> <beans > <aop:config proxy-target-class="true" > <aop:pointcut id="intranetMonitoringScope" expression="(execution(public * com.abc.intranet.web.servlet.IntraAssetServlet.doGet(..))) || (execution(public * com.abc.intranet.web.servlet.SimpleBean.log*(..))) " /> <aop:aspect id="myIntranetMonitoringAspect" ref="intranetMonitoringAspect"> <aop:around method="monitor" pointcut-ref="intranetMonitoringScope" /> </aop:aspect> </aop:config> <bean id="intranetMonitoringAspect" class="com.abc.intranet.web.servlet.SimpleAroundAspect" /> </beans>IntraAssetServlet classCode:package com.abc.intranet.web.servlet; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; public class SimpleAroundAspect { private org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(SimpleAroundAspect.class); /** * Default constructor */ public SimpleAroundAspect() { super(); } public Object monitor(ProceedingJoinPoint thisJoinPoint) throws Throwable { Signature signature = thisJoinPoint.getSignature(); log.info("Before Call to proceed on joinpoint: " + signature.getDeclaringTypeName() + "." + signature.getName()); Object result; try { result = thisJoinPoint.proceed(); } finally{ log.info("After Call to proceed on joinpoint: " + signature.getDeclaringTypeName() + "." + signature.getName()); } return result; } }Code:package com.abc.intranet.web.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; public class IntraAssetServlet extends HttpServlet { /** Support serialization */ private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(IntraAssetServlet.class); private SimpleBean bean = null; public void setSimpleBean(SimpleBean theBean){ bean = theBean; } public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { log.info("Inside the IntraAssetServlet before calling the beans logSomething method."); bean.logSomething(); log.info("Inside the IntraAssetServlet after calling the beans logSomething method."); } }


Reply With Quote