Spring注解备忘

记录一下目前知道的注解

1、使用 @Configuration 注释告诉 Spring,这是核心的 Spring 配置文件,并通过 @Bean 定义 bean。
2、@Import 导入多个@Configuration

3、@Scope("prototype")定义bean的作用域

4、@Required确保值被设置

5、@Value直接注入

6、@Component,@Service,@Controller,@Repository注解的类,并把这些类纳入进spring容器中管理。
@Service用于标注业务层组件
2、@Controller用于标注控制层组件(如struts中的action)
3、@Repository用于标注数据访问组件,即DAO组件.
4、@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。

7、常见AspectJ的注解:
@Aspect
@Before – 方法执行前运行
@After – 运行在方法返回结果后
@AfterReturning – 运行在方法返回一个结果后,在拦截器返回结果。
@AfterThrowing – 运行方法在抛出异常后,
@Around – 围绕方法执行运行,结合以上这三个通知。

8、@transactional使得方法具有事务特性
9、@RequestHeader get请求或post都有请求头,用@RequestHeader注解来获取。

原文地址:https://www.cnblogs.com/encode/p/5912014.html