Spring 的 Bean 管理:( 注解方式)

 Spring 的 Bean 管理:( 注解方式)

1. Spring 的 Bean 管理 :(注解方式)

步骤一: 下载 Spring 的开发包:

https://mvnrepository.com/

步骤二: 创建 web 项目, 引入 Spring 的开发包

Spring 的 Bean 管理:( 注解方式)

步骤三: 引入相关配置文件

applicationContent.xml

Spring 的 Bean 管理:( 注解方式)

步骤四: 编写相关的类

Spring 的 Bean 管理:( 注解方式)

Spring 的 Bean 管理:( 注解方式)

步骤五: 配置注解扫描

<!-- Spring 的注解开发:组件扫描(类上注解: 可以直接使用属性注入的注解) -->

Spring 的 Bean 管理:( 注解方式)
在相关的类上添加注解:

Spring 的 Bean 管理:( 注解方式)

编写测试类:

Spring 的 Bean 管理:( 注解方式)

 

效果图:

Spring 的 Bean 管理:( 注解方式)

 Spring 集成junit4 测试

导入spring-test.jar包

@RunWith(SpringJUnit4ClassRunner.class) 使用junit4进行测试
@ContextConfiguration() 加载spring相关的配置文件

Spring 的 Bean 管理:( 注解方式)

Spring 的 Bean 管理:( 注解方式)

Spring 的 Bean 管理的中常用的注解: :

@Component: 组件.( 作用在类上)

Spring 的 Bean 管理:( 注解方式)

属性注入的注解:( 使用注解注入的方式, 可以不用提供 set 方法.)

Spring 的 Bean 管理:( 注解方式)

Bean 的作用范围的注解:

Spring 的 Bean 管理:( 注解方式)

Bean 的生命周期的配置

Spring 的 Bean 管理:( 注解方式)

Spring 的 Bean 管理的方式的比较:

Spring 的 Bean 管理:( 注解方式)