Originating from:http://blog.csdn.net/qq_26525215
@EnableAspectJAutoProxy
@EnableAspectJAutoProxy annotations Activate aspect automatic proxy
< Aop:aspectj-autoproxy />
Turn on support for ASPECTJ Auto Proxy.
When using automatic proxy for AOP, if you understand the dynamic agent of Java, it is easy to familiarize yourself with the automatic agent of AOP.
@EnableAsync
@EnableAsync annotations turn on support for async methods.
This is believed to be more familiar to everyone. It should all be understood for asynchrony.
Not very familiar, you can read this blog:-There are examples
Spring Spring Advanced topic-multithreading-taskexecutor
@EnableScheduling
@EnableScheduling annotations turn on support for scheduled tasks.
That is the literal meaning, open the support of the scheduled task!
It is generally necessary to @scheduled annotated mates.
See this blog for details:
Spring Spring Advanced Topics-Scheduled Tasks [email protected]
@EnableWebMVC
@EnableWebMVC annotations are used to turn on configuration support for Web MVC.
That's when you write spring MVC.
@EnableConfigurationProperties
@EnableConfigurationProperties annotations are used to turn on support for @configurationproperties annotation configuration beans.
That is, the @enableconfigurationproperties annotation tells Spring Boot to support @configurationproperties
@EnableJpaRepositories
@EnableJpaRepositories annotations Open the support for spring Data JPA repostory.
The spring data JPA framework, which focuses on the only business logic code that is not simplified to the spring, has been saved by the developer's only remaining implementation of the persistence layer's business logic, and the only thing to do is to declare the interface for the persistence layer, and the rest to spring Data JPA To help you finish!
Simply put, Spring data JPA is the framework for persisting data.
@EnableTransactionManagement
@EnableTransactionManagement annotations turn on support for annotated transactions.
Note @enabletransactionmanagement notifies spring that the class @Transactional annotated is surrounded by the facets of the transaction. So the @transactional can be used.
@EnableCaching
Annotation-enabled cache support @EnableCaching annotations
With these simple @enable*, you can turn on the support of a feature to avoid having to configure a large amount of code, greatly reducing the difficulty of use.
Together we observe the source code of these @enable* annotations, and you can see that all annotations have a @import annotation.
@Import annotations are used to import configuration classes, which means that these auto-open implementations actually import some automatically configured beans.
These import configurations are mainly divided into the following three types.
Three types of @Import annotation import configuration First class: Direct Import Configuration Class
////Source code recreated from a. class file by IntelliJ idea//(Powered by Fernflower Decompiler)// Packageorg.springframework.scheduling.annotation;Importjava.lang.annotation.Documented;ImportJava.lang.annotation.ElementType;Importjava.lang.annotation.Retention;ImportJava.lang.annotation.RetentionPolicy;ImportJava.lang.annotation.Target;ImportOrg.springframework.context.annotation.Import;Importorg.springframework.scheduling.annotation.SchedulingConfiguration; @Target ({elementtype.type}) @Retention ( Retentionpolicy.runtime) @Import ({schedulingconfiguration.class}) @Documented Public@Interfaceenablescheduling {}
Direct import Configuration Class Schedulingconfiguration, this class annotated @configuration, and registered a scheduledannotationprocessor bean, the source code is as follows:
/** Copyright 2002-2015 the original author or authors. * Licensed under the Apache License, Version 2.0 (the "Licens E "); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * *http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable or agreed to writing, software * Distributed under the License is distribute D on ' As is ' BASIS, * without warranties or CONDITIONS of any KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Packageorg.springframework.scheduling.annotation;Importorg.springframework.beans.factory.config.BeanDefinition;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;ImportOrg.springframework.context.annotation.Role;Importorg.springframework.scheduling.config.TaskManagementConfigUtils;/** * {@code@Configuration} class that registers a {@linkscheduledannotationbeanpostprocessor} * bean capable of processing Spring ' s @{@linkscheduled} annotation. * * <p>this configuration class is automatically imported when using the * @{@linkenablescheduling} annotation. See {@code@EnableScheduling} ' s Javadoc * for complete usage details. * * @authorChris Beams *@since3.1 *@seeenablescheduling *@seeScheduledannotationbeanpostprocessor*/@Configuration @role (beandefinition.role_infrastructure) Public classschedulingconfiguration {@Bean (name=taskmanagementconfigutils.scheduled_annotation_processor_bean_name) @Role (beandefinition.role_ INFRASTRUCTURE) Publicscheduledannotationbeanpostprocessor scheduledannotationprocessor () {return Newscheduledannotationbeanpostprocessor (); }}
Class II: Select Configuration classes based on conditions
Enableasync Annotation Core code:
@Target (Elementtype.type) @Retention (retentionpolicy.runtime) @Documented @import (asyncconfigurationselector.class) Public@InterfaceEnableasync {Class<?extendsAnnotation> Annotation ()defaultAnnotation.class; BooleanProxytargetclass ()default false; Advicemode mode ()defaultAdvicemode.proxy; intOrder ()defaultordered.lowest_precedence;}
Asyncconfigurationselector Select the configuration class that you want to import by using conditions
The root interface of the asyncconfigurationselector is Importselector, and this interface needs to override the Selectimports method, in which the pre-condition is determined.
In the following source code, if Advicemode is Porxy, it returns proxyasyncconfiguration this configuration class.
If Activemode is AspectJ, the Aspectjasyncconfiguration configuration class is returned.
The source code is as follows:
Public classAsyncconfigurationselectorextendsAdvicemodeimportselector<enableasync> { Private Static FinalString async_execution_aspect_configuration_class_name = "Org.springframework.scheduling.aspectj.AspectJAsyncCo Nfiguration "; /** * {@inheritDoc} * @return {@linkProxyasyncconfiguration} or {@codeAspectjasyncconfiguration} for * {@codePROXY} and {@codeASPECTJ} values of {@linkEnableasync#mode ()}, respectively*/@Override Publicstring[] Selectimports (Advicemode advicemode) {Switch(advicemode) { CasePROXY:return NewString[] {proxyasyncconfiguration.class. GetName ()}; CaseASPECTJ:return Newstring[] {async_execution_aspect_configuration_class_name}; default: return NULL; } }}
Class III: Dynamically registering beans
@Target (Elementtype.type) @Retention (retentionpolicy.runtime) @Documented @import (Aspectjautoproxyregistrar. class ) public @Interface enableaspectjautoproxy { boolean Defaultfalse;}
Aspectjautoproxyregistrar the Importbeandefinitionregistrar interface beforehand, The role of Importbeandefinitionregistrar is to automatically add beans to an existing configuration class at run time by overriding the method:
@Override Public void registerbeandefinitions (Annotationmetadata importingclassmetadata, beandefinitionregistry Registry)
Where the Annotationmetadata parameter is used to obtain annotations on the current configuration class, and the beandefinittionregistry parameter is used to register the bean.
The source code is as follows:
classAspectjautoproxyregistrarImplementsImportbeandefinitionregistrar {/*** Register, escalate, and configure the AspectJ auto Proxy creator based on the value * of the @{@linkenableaspectjautoproxy#proxytargetclass ()} attribute on the importing * {@code@Configuration} class. */@Override Public voidregisterbeandefinitions (Annotationmetadata importingclassmetadata, beandefinitionregistry registry) { Aopconfigutils.registeraspectjannotationautoproxycreatorifnecessary (registry); Annotationattributes Enableajautoproxy=annotationconfigutils.attributesfor (Importingclassmetadata, Enableaspectjautoproxy.class); if(Enableajautoproxy.getboolean ("Proxytargetclass") {aopconfigutils.forceautoproxycreatortouseclassproxying (registry); } }}
Spring Advanced topic [email protected] * * * How annotations work