用于创建对象==<bean>
value属性指定值,默认值是当前类名-首字母小写
1. @Component
2. @Controller:表现层
3. @Service:业务层
4. @Repository:持久层
用于注入数据==<property>
1. @Autowired:类型匹配->名称匹配
2. @Autowired
@Qualifier("bean-id"):名称匹配
3. @Resource(name="bean-id"):名称匹配
4. @Value:基本类型(可以用SpEl)${}
用于改变作用范围==scope
1. @Scope [singleton|prototype|request|session|globalsession]
用于生命周期==init-method|destroy-method
1. @PostConstruct
2. @PreDestroy
用于配之类==beans.xml
1. @Configuration
2. @ComponentScan("com.example") == context:component-scan
用于导入其他配之类
1. @Import(com.example.jdbc.JdbcConfig.class) :JdbcConfig不需要@Configuration修饰
2. @PropertySource("classpath:config.properties"):当@Value使用SpEl时导入配置文件
用于JUnit整合Spring
1. @RunWith(SpringJUnit4ClassRunner.class)
2. @ContextConfiguration(classes = com.example.config.Config.class) | @ContextConfiguration(locations = "classpath:bean.xml")
用于开启AOP注解
1. @EnableAspectJAutoProxy
AOP注解
1. @Aspect:指定类是一个切面
2. @Pointcut("execution(* com.example.service.impl.*.*(..))")
private void pt1(){}:指定切入点表达式
3. @Before("pt1()"):指定前置通知方法
4. @AfterReturning("pt1()"):指定后置通知方法
5. @AfterThrowing("pt1()"):指定异常通知方法
6. @After("pt1()"):指定最终通知方法
7. @Around("pt1()"):指定环绕通知方法
事务
1. @EnableTransactionManagement:开启事务支持
2. @Transactional:在类或方法上,指明事务支持