-
@Component
作用:为一个类创建bean
位置:类上
-
@ComponentScan
作用:对@Component进行扫描
位置:类
-
@Configuration
作用:声明当前类为配置类
位置:类
-
@ContextConfiguration
作用:用于测试,声明加载ApplicationContext的方式(xml/java config)
位置:测试类
-
@Autowired
作用:自动装配
位置:构造函数、字段、方法
JavaDocs说明
Marks a constructor, field, setter method or config method as to be autowired by Spring’s dependency injection facilities;
Only one constructor (at max) of any given bean class may carry this annotation, indicating the constructor to autowire when used as a Spring bean. Such a constructor does not have to be public.
Fields are injected right after construction of a bean, before any config methods are invoked. Such a config field does not have to be public.
Config methods may have an arbitrary name and any number of arguments; each of those arguments will be autowired with a matching bean in the Spring container. Bean property setter methods are effectively just a special case of such a general config method. Such config methods do not have to be public.
In the case of multiple argument methods, the ‘required’ parameter is applicable for all arguments.
In case of a {@link java.util.Collection} or {@link java.util.Map} dependency type, the container will autowire all beans matching the declared value type. In case of a Map, the keys must be declared as type String and will be resolved to the corresponding bean names.
-
@Bean
作用:声明当前方法返回一个Bean
位置:方法
-
@Import
作用:配置类导入其他配置类
位置:类
-
@ImportResource
作用:配置类导入其他xml配置
位置:类
-
@Scope
作用:设置Bean的作用域
位置:声明Bean的地方(例如声明@Component的类、 配置类@Configuration的@Bean的方法)
-
@PropertySource
作用:加载配置文件(例如国家名称、作者名称这种东西)
位置:类
-
@Aspect
作用:声明一个切面
位置:类
-
(1) @Before
作用:通知方法会在目标方法调用前执行
(2) @AfterReturning
作用:通知方法会在目标方法返回后执行
(3) @AfterThrowing
作用:通知方法会在目标方法抛出异常后执行
(4) @After
作用:通知方法会在目标方法返回后或抛出异常后执行(相当于@AfterThrowing和@AfterReturning的结合体)
(5) @Around
作用:通知方法会将目标方法__环绕__起来
__共同__作用位置:方法
-
@EnableAspectJAutoProxy
作用:启用AspectJ自动代理的功能(否则AOP用不上)
位置:类
-
@EnableWebMVC
作用:开启Web MVC的__配置__支持
位置:(配置)类(@Configuration的类)
-
@Controller
作用:为一个类创建bean(作用和@Component等效,但是可以显示标注出用作Controller的类)
位置:用于作为Controller的类
-
@RequestMapping
作用:映射请求的URL路径
位置:作为Controller的类或方法(如果类和方法上都使用了,它们对应的路径会叠加)
-
@ResponseStatus
作用:将异常映射为特定的状态码
位置:异常类上(扩展了Exception的类)或者要抛出异常的方法
-
@ExceptionHandler
作用:用于标注一个处理异常的方法,通常会返回一个错误页面的URL String
位置:方法
-
@ControllerAdvice
作用:典型应用是标注一个统一处理异常的方法的类
位置:类
-
@EnableWebMvcSecurity
作用:启用SpringMVC的Web安全功能
位置:(配置)类(@Configuration的类)
-
@Repository
作用:为一个类创建bean(作用和@Component等效,但是可以显示标注出用作DAO层的类)
位置:用于作为DAO的类
-
@Value
作用:为属性注入值
位置:字段
-
@ResponseBody
作用:将返回值放入response,而不是返回某个页面
位置:类或方法
-
@RunWith
作用:用于对JUnit测试的支持
位置:类
-
@ContextConfiguration
作用:测试时加载指定的配置文件
位置:类
-
@Profile
作用:设定某个bean属于哪个profile,便于运行时选择环境
位置:(配置)类(@Configuration)或返回Bean的方法(@Bean)
-
@Conditional
作用:对于满足一定条件的bean进行实例化,否则忽略这个bean
位置:(配置)类(@Configuration)或返回Bean的方法(@Bean)