如何使用注解替换mvc:resources命名空间
我正在使用注释构建一个项目来完成配置工作。
当我这样做时,我找不到使用注释来替换 mvc:resources 命名空间标签的方法。
我可以提供一个关于我想要的例子。
示例:使用注解替换
。
@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;
}
... ...
}
那么基于上面的例子,有没有办法使用注解来替换
命名空间标签呢?
提前致谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要@EnableWebMvc。但这是 Spring 3.1 的功能!
@查看此博客: Spring 3.1 M2:Spring MVC 增强
You need
@EnableWebMvc
. But this is a Spring 3.1 Feature!@see this Blog: Spring 3.1 M2: Spring MVC Enhancements