views:

246

answers:

3

Up to now, <mvc:annotation-driven /> has caused plenty of trouble for me, so I would like to get rid of it. Although the spring framework docs clearly say what it is supposed to be doing, a listing of tags actually summar <mvc:annotation-driven /> is lacking.

So I'm stuck with removing <mvc:annotation-driven /> and now getting the error

WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/webapp/trainees] in DispatcherServlet with name 'workoutsensor'

for all Urls supposed to be resolved by the controller classes (in this case: ./trainees). Any suggestion where I can read more about <mvc:annotation-driven />? I desperately would like to know what tags exactly are represented by <mvc:annotation-driven />.

+3  A: 

If you want to avoid the mvc:annotation-driven tag, you can simply create DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter beans yourself, but it sounds like it would be better to get to the root of your troubles with the tag itself.

What are the symptoms of your problem? What are you trying to do with your Spring MVC application?

If you want to know what's going on under the covers when you use mvc:annotation-driven, see the AnnotationDrivenBeanDefinitionParser.parse() method.

James Earl Douglas
"What are the symptoms of your problem?" - O, it's just that whenever I customize a spring security interface (e.g. UserDetailsManager) I get a "double defined" error. Or when I try and define my own aspects, mine are never read because spring uses its own. Furthermore, I feel better having some more control over what I code. Convention-over-configuration is a great thing ... if you know what the convention is ;-)
+4  A: 

Look at the source code of org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser

And you can see which beans it is defining. I've done this 'exercise' (not for all of them, but for those I need), so here are they:

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="webBindingInitializer">
            <bean class="com.yourpackage.web.util.CommonWebBindingInitializer" />
        </property>
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
                <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
                <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
                <bean class="org.springframework.http.converter.feed.AtomFeedHttpMessageConverter" />
                <bean class="org.springframework.http.converter.feed.RssChannelHttpMessageConverter" />
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
                <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
                <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
                <!-- bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" /-->
            </list>
        </property>
    </bean>
<bean id="handlerMapping"
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">

Now, above you see the CommonWebBindingInitializer. You have to create this class the looks like that, in order to use conversion and validation:

public class CommonWebBindingInitializer implements WebBindingInitializer {

    @Autowired
    private Validator validator;

    @Autowired
    private ConversionService conversionService;

    @Override
    public void initBinder(WebDataBinder binder, WebRequest request) {
        binder.setValidator(validator);
        binder.setConversionService(conversionService);
    }

}

And this works fine for me so far. Feel free to report any problems with it.

Bozho
Thanks Bozho, that is just the input I need. I am quite sure that I will run into further config problems, in particular, implementing <remember-me/>. I won't hesitate reporting them ;-)
Ah, there is the Fisheye link I was looking for. :]
James Earl Douglas
A: 

WOW the initializer idea helped very much :) Thanks bozho

Gabrianoo