1、 创建一个maven项目
2、导入依赖坐标
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.10.RELEASE</version> </dependency>
3、添加配置文件或者使用注解注入bean
(1) 创建配置文件applicationcontext.xml添加配置
(2)纯注解开发,相关注解
bean生成类
@Component
@Controller
@Service
@Repository
注入bean的注解
@Autowired 自动装配注解,在需要注入的bean上添加
@Qualifier("bean的id") 配合Autowired可以匹配指定bean
@Resource("bean的id") 功能和@Autowired+@Qualifier("bean的id")一样的功能
@Primary在类