Spring @Enable模块驱动原理及使用实例
Spring@Enable模块概览
框架实现
@Enable注解模块
激活模块
@EnableWebMvc
WebMVC模块
@EnableTransactionManagement
事务管理模块
@EnableCaching
Caching模块
@EnableMBeanExport
JMX模块
@EnableAsync
异步处理模块
@EnableWebFlux
WebFlux模块
@EnableAspectJAutoProxy
AspectJ代理模块
@EnableAutoConfiguration
自动装配
@EnableManagementContext
Actuator管理模块
@EnableConfigurationProperties
配置属性绑定模块
@EnableOAuth2Sso
OAuth2 单点登录模块
@EnableEurekaServer
Eureka服务器模块
@EnableConfigServer
配置服务器模块
@EnableFeignClients
Feign 客户端模块
@EnableZuulProxy
服务网关Zuul 模块
@EnableCircuitBreaker
服务熔断模块
理解@Enable以@EnableWebMVC为例进行理解
定义如下:
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Documented @Import(DelegatingWebMvcConfiguration.class) public@interfaceEnableWebMvc{ }
发现该注解中引入的DelegatingWebMvcConfiguration.class
@Configuration(proxyBeanMethods=false)
publicclassDelegatingWebMvcConfigurationextendsWebMvcConfigurationSupport{
...
}
publicclassWebMvcConfigurationSupportimplementsApplicationContextAware,ServletContextAware{ @Bean @SuppressWarnings("deprecation") publicRequestMappingHandlerMappingrequestMappingHandlerMapping( @Qualifier("mvcContentNegotiationManager")ContentNegotiationManagercontentNegotiationManager, @Qualifier("mvcConversionService")FormattingConversionServiceconversionService, @Qualifier("mvcResourceUrlProvider")ResourceUrlProviderresourceUrlProvider){ ... } ... }
其中实现类WebMvcConfigurationSupport.java中预定义了多个SpringBean对象,
随着@EnableWebMVC驱动注解的加载而被加载到Spring上下文中从而实现SpringWebMVC的功能。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。