Results 1 to 3 of 3

Thread: Aspect on Servlet Doesn't Execute

  1. #1
    Join Date
    Nov 2008
    Posts
    7

    Default Aspect on Servlet Doesn't Execute

    Hello - I'm trying to use a spring aop aspect with a servlet.

    I have the following spring configuration:

    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <aop:config>
    <aop:pointcut id="monitorScope" expression="(execution(* com.probuild.intranet.web.servlet..doGet(..)))" />

    <aop:aspect id="myMonitoringAspect" ref="monitoringAspect">
    <aop:around method="monitor" pointcut-ref="monitorScope" />
    </aop:aspect>

    </aop:config>

    <bean id="monitoringAspect" class="com.probuild.aspects.AroundAspect" />

    and the following web configuration:

    <servlet>
    <servlet-name>AssetServlet</servlet-name>
    <servlet-class>
    com.probuild.intranet.web.servlet.IntraAssetServle t
    </servlet-class>
    <init-param>
    <param-name>folderFilter</param-name>
    <param-value>/intranet/resources</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>AssetServlet</servlet-name>
    <url-pattern>/asset</url-pattern>
    </servlet-mapping>


    When deployed, the monitoringAspect does not get executed when the doGet method is called. I've tried a variety of configurations but as of yet have not been able to find the sweet spot. Does anyone see anything obviously wrong with this config? Or better still, does anyone have any suggestions that I might try?

    Thanks in advance for your help.

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Quote Originally Posted by kconway View Post
    ...
    When deployed, the monitoringAspect does not get executed when the doGet method is called. I've tried a variety of configurations but as of yet have not been able to find the sweet spot. Does anyone see anything obviously wrong with this config? Or better still, does anyone have any suggestions that I might try?

    Thanks in advance for your help.
    Spring AOP is proxy-based. That means that the client of AOP-advised bean should perform the call not against the bean itself but on its proxy. When the proxy is called AOP logic is applied if necessary and the call is dispatched to the backing bean. Check corresponding reference section about that - 6.6.1. Understanding AOP proxies. It seems that your call is processed on the 'raw' bean.

    You can check your configuration in order to make sure that the proxy processes the call to be AOP-advised. Another approach is to use aspectj-weaving.

  3. #3
    Join Date
    Nov 2008
    Posts
    7

    Default

    Thanks for the response. Turns out that what I really needed to do was rtfm :-D I think I have a solution for my problem. Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •