Announcement Announcement Module
Collapse
No announcement yet.
DefaultAdvisorAutoProxyCreator & Spring MVC Beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      Thank you very much for you help.

      David

      Comment

      Working...
      X