I am building a project using annotation to do the configuration job.
And when I doing this, I cannot find a way to use annotation to replace mvc:resources namespace tag.
I can provide an example about what I want.
Example: use annotation to replace <mvc:annotation-driven />
.
@Configuration
@Lazy(false)
public class MVCContainerConfig
{
/**
* Define (MVC) Annotation Method Handler Adapter. (Same as <mvc:annotation-driven /> in XML)
*/
@Bean
public AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter()
{
ConfigurableWebBindingInitializer configurableWebBindingInitializer = new ConfigurableWebBindingInitializer();
configurableWebBindingInitializer.setValidator(localValidatorFactoryBean());
AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter = new AnnotationMethodHandlerAdapter();
annotationMethodHandlerAdapter.setWebBindingInitializer(configurableWebBindingInitializer);
annotationMethodHandlerAdapter.setMessageConverters(new HttpMessageConverter[]{
new BufferedImageHttpMessageConverter(),
new ByteArrayHttpMessageConverter(),开发者_如何转开发
new FormHttpMessageConverter(),
new ResourceHttpMessageConverter(),
new StringHttpMessageConverter(),
new AtomFeedHttpMessageConverter(),
new RssChannelHttpMessageConverter(),
new MappingJacksonHttpMessageConverter(),
new Jaxb2RootElementHttpMessageConverter(),
new MarshallingHttpMessageConverter(),
new XmlAwareFormHttpMessageConverter()
});
return annotationMethodHandlerAdapter;
}
... ...
}
So based on the above example, is there a way to use annotation to replace <mvc:resources />
namespace tag?
Thanks in advance!
You need @EnableWebMvc
. But this is a Spring 3.1 Feature!
@see this Blog: Spring 3.1 M2: Spring MVC Enhancements
精彩评论