Results 1 to 3 of 3

Thread: DefaultAdvisorAutoProxyCreator & Spring MVC Beans

  1. #1
    Join Date
    May 2008
    Posts
    2

    Default DefaultAdvisorAutoProxyCreator & Spring MVC Beans

    Hi,

    I am currently trying to add some advice to a bean that is configured in my x-servlet.xml file.

    I have the following configuration in my x-servlet.xml file

    <bean class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/start">loginController</prop>
    </props>
    </property>
    </bean>

    <bean id="loginController" class="com.fmr.spring.sample.accountviewer.control ler.LoginController">
    ........
    </bean>

    I want to add advice to the onBindAndValidate method of any controller configured in this file.

    In another Spring configuration file I have the advice configured as follows

    <bean class="org.springframework.aop.framework.autoproxy .DefaultAdvisorAutoProxyCreator">
    <property name="usePrefix" value="false"/>
    </bean>

    <bean id="defaultValidationAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="advice" ref="defaultValidationAdvice"/>
    <property name="pattern" value=".*onBindAndValidate"/>
    </bean>

    <bean id = "defaultValidationAdvice" class="com.fmr.spring.sample.accountviewer.default validation.DefaultValidationAdvice">
    ...
    </bean>

    This advice is not being executed however if i add this advice to a different method of a bean that is defined within a Spring context file then it works fine.

    I noticed from the logs that 2 DefaultListableBeanFactory are used to create the beans, 1 for the application context beans and 1 for the beans defined for spring mvc within the x-servlet file.
    The DefaultAdvisorAutoProxyCreator seems to be working on beans created within the application context (first bean factory) but not the second.

    Does anyone know of anyway of adding advice to controller beans defined within you x-servlet.xml file? Preferably through configuration.

    I have tried defining the advice beans within the x-servlet.xml file as well as configuring x-servlet.xml as a contextConfigLocation in web.xml but neither have worked.

    Any help would be greatly appreciated
    Thanks
    David

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    I suggest you read chapter 6.6.1 regarding how spring proxies work.

    You can only intercept method calls INTO the object, for a Controller that is unfortunatly only 1 method handleRequest, all the other methods are internal method calls and don't pass the proxy.

    If you want to intercept those methods you will need to use loadtime weaving to advice the classes and not the proxy based mechanism.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2008
    Posts
    2

    Default

    Thank you very much for you help.

    David

Posting Permissions

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