May 13th, 2008, 09:15 AM
DefaultAdvisorAutoProxyCreator & Spring MVC Beans
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">
<bean id="loginController" class="com.fmr.spring.sample.accountviewer.control ler.LoginController">
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 id="defaultValidationAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
<property name="advice" ref="defaultValidationAdvice"/>
<property name="pattern" value=".*onBindAndValidate"/>
<bean id = "defaultValidationAdvice" class="com.fmr.spring.sample.accountviewer.default validation.DefaultValidationAdvice">
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
May 13th, 2008, 09:28 AM
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.
May 13th, 2008, 09:30 AM
Thank you very much for you help.