Spring依赖注入
一、配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package=""/>
</beans>
二、自动装配注解
1. @Autowired
2. @Qualifier (name = "")
3. @Resource (name = "")
4. @Component
5. @Value
三、Component 的衍生注解
1. @Repository
2. @Service
3. @controller
四、作用域相关注解
@Scope("")
- singleton
- prototype
五、完全使用Java配置
@Configuration
@ComponentScan("")
@import("")
@Bean
public User user(){
return new User();
}