Spring @EnableWebMvc
来源:互联网 发布:易娱网络太古汇39楼 编辑:程序博客网 时间:2024/06/11 23:23
org.springframework.web.servlet.config.annotation
Annotation Type EnableWebMvc
@Retention(value=RUNTIME)@Target(value=TYPE)@Documented@Import(value=DelegatingWebMvcConfiguration.class)public @interface EnableWebMvc
Add this annotation to an @Configuration
class to have the Spring MVC configuration defined in WebMvcConfigurationSupport
imported:
@Configuration @EnableWebMvc @ComponentScan(basePackageClasses = { MyConfiguration.class }) public class MyWebConfiguration { }
Customize the imported configuration by implementing the WebMvcConfigurer
interface or more likely by extending the WebMvcConfigurerAdapter
base class and overriding individual methods:
@Configuration @EnableWebMvc @ComponentScan(basePackageClasses = { MyConfiguration.class }) public class MyConfiguration extends WebMvcConfigurerAdapter { @Override public void addFormatters(FormatterRegistry formatterRegistry) { formatterRegistry.addConverter(new MyConverter()); } @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { converters.add(new MyHttpMessageConverter()); } // More overridden methods ... }
If the customization options of WebMvcConfigurer
do not expose something you need to configure, consider removing the @EnableWebMvc
annotation and extending directly from WebMvcConfigurationSupport
overriding selected @Bean
methods:
@Configuration @ComponentScan(basePackageClasses = { MyConfiguration.class }) public class MyConfiguration extends WebMvcConfigurationSupport { @Override public void addFormatters(FormatterRegistry formatterRegistry) { formatterRegistry.addConverter(new MyConverter()); } @Bean public RequestMappingHandlerAdapter requestMappingHandlerAdapter() { // Create or delegate to "super" to create and // customize properties of RequestMapingHandlerAdapter } }
- Since:
- 3.1
- Author:
- Dave Syer, Rossen Stoyanchev
- See Also:
WebMvcConfigurer
,WebMvcConfigurerAdapter
0 0
- Spring @EnableWebMvc
- @EnableWebMVC
- @EnableWebMvc 、WebMvcConfigurationSupport和WebMvcConfigurationAdapter
- @EnableWebMvc 与 @EnableAutoConfiguration 的关系
- 解析@EnableWebMvc 、WebMvcConfigurationSupport和WebMvcConfigurationAdapter
- Spring
- Spring
- spring
- spring
- spring
- spring
- Spring
- spring
- spring
- Spring
- Spring
- spring
- Spring
- Android 在锁屏界面添加未读短信和电话提醒
- 黑马程序员——Java基础---深层拷贝(数组、ArrayList)
- 基于OpenCV的圆斑检测方法
- 堆优化的Dijkstra算法
- [c++]复数的运算符重载
- Spring @EnableWebMvc
- [网络编程] Linux网络编程经典书籍
- 多播
- 手机充电误区及该如何充电
- springMVC bootstarp 用户权限基础框架+即时通讯
- 最长单调递增子序列——动态规划
- 使用pkg-config升级和切换glib库
- Core Graphics图形变换
- pythonanywhere下django无法匹配url问题解决