注解类型
使用方式:
1、配置中开启扫描
2、添加依赖spring-context(因为spring-webmvc中包含spring-context)
创建对象:
@Component普通创建bean对象
@Repository Dao层
@Service Service层
@Controller Controller层
赋值:
@value 简单类型注入
@Autowired 引用类型的注入,默认是bytype
@Qualifier 与@Autowired配合是byname类型
@Resource 可bytype可byname
@Resource(name=" ") 是byname
注意需要导入依赖
<dependency> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> <version>1.3.2</version> </dependency>