spring注解驱动开发

容器

AnnotationConfigApplicationContext
	配置类
	包扫描
组件添加
	@ComponentScan
	@Bean
		指定初始化销毁
		初始化其他方式
			InitializingBean(初始化设置值之后)
			DisposableBean(销毁)
			JSR250
				@PostConstruct
				@PreDestroy
		BeanPostProcessor
	@Configuration
	@Component
	@Service
	@Controller
	@Repository
	@Conditional
	@Primary
	@Lazy
	@Scope
	@Import
	ImportSelector
	工厂模式
		FactoryBean
			&beanName获取Factory本身

组件赋值

	@Value
	@Autowired
		@Qualifier
		其他方式
			@Resources(JSR250)
			@Inject(JSR330,需要导入javax.inject)
	@PropertySource
	@PropertySources
	@Profile
		Environment
		-Dspring.profiles.active=test

组件注入

	方法参数
	构造器注入
	ApplicationContextAware
		ApplicationContextAwareProcessor
	xxxAware
AOP
	@EnableAspectJAutoProxy
	@Before/@After/@AfterReturning/@AfterThrowing/@Around
	@Pointcut
声明式事务
	@EnableTransactionManagement
	@Transactional

扩展原理

BeanFactoryPostProcessor
	Spring容器标准初始化之后执行(BeanPostProcessor之前),此时bean还未创建
	Spring容器初始化两大步
		1、加载保存和读取所有bean配置
		2、按照之前的配置创建bean
BeanDefinitionRegistryPostProcessor
	BeanFactoryPostProcessor子类,可自定义添加bean定义
	BeanDefinetionRegistry
		BeanDefinetionBuilder
ApplicationListener
	@EventListener
Spring容器创建过程

web

servlet3.0
	ServletContainerInitializer
	Registration
		ServletRegistration
		FilterRegistration
	ServletContext
异步请求
	servlet3.0异步处理
	返回Callable
	返回DeferredResult

大纲图示