I am trying to implement converter in SpringMVC and configure it like in How to configure Spring ConversionService with java config? and some weird things happened.
ApplicationConfiguration.java
@Configuration
@EnableWebMvc
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry formatterRegistry) {
formatterRegistry.addConverter(new StringToFoo());
formatterRegistry.addConverter(new FooToString());
}
}
I have a jsp with a form to pass a Foo object to controller.
And I have <mvc:annotation-driven/>
and component-scan in xml.
It turns out that the code I quoted was executed at init, but the converters were not called when passing from jsp to controller,
When I delete annotation-driven, everything works, converter was correctly called in my controller. However, before I added WebMvcConfigurerAdapter to the proejct, I had to include annotation-driven to init servlet.
So my questions:
What does annotation-driven do? Does WebMvcConfigurerAdapter (or the annotations used) have conflict with annotation-driven?