纯注解开发

纯注解开发

spring3.0升级了纯注解开发模式,使用Java类替代配置文件,开启了Spring快速开发赛道。

   package com.charley.config;
   
   import org.springframework.context.annotation.ComponentScan;
   import org.springframework.context.annotation.Configuration;
   
   @Configuration
   @ComponentScan("com.charley")
   public class SpringConfig {
   }
   ```
   
- @Configuration注解用于设定当前类为配置类
- @ComponentScan注解用于设定扫描路径,此注解只能添加一次,多个数据请用数组格式
- 读取Spring核心配置文件初始化容器对象切换为读取Java配置类初始化容器对象
   
   ```java
   ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
   ```