【问题标题】:How to use annotation to replace mvc:resources namespace如何使用注解替换 mvc:resources 命名空间
【发布时间】:2011-12-08 22:09:53
【问题描述】:

我正在使用注释构建一个项目来完成配置工作。

当我这样做时,我找不到使用注释来替换 mvc:resources 命名空间标记的方法。

我可以举例说明我想要什么。

示例:使用注解替换<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;
    }

    ... ...
}

那么基于上面的例子,有没有办法使用注解来替换&lt;mvc:resources /&gt;命名空间标签呢?

提前致谢!

【问题讨论】:

    标签: xml spring resources annotations spring-webflow


    【解决方案1】:

    您需要@EnableWebMvc。但这是 Spring 3.1 的功能!

    @查看此博客:Spring 3.1 M2: Spring MVC Enhancements

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      相关资源
      最近更新 更多