Sping容器里面加载Properties文件
<context:preperty-p;aceholder location=“classpath* : *.propeties”/>
然后配置命名空间
Spring原始注解
1:@Component(""):让Spring产生对象
2.@Autowired
@Qualifier("")
自动注入
注:需要配置组件扫描
<context:component-scan base-package=“包路径”/>//包括扫描子包
@Controller 使用在web层类上用语实例化Bean
@Repository("")语义化用于dao层让SPring产生对象
@Service("")语义化用语Service层让Spring产生对象
@Resoure(name="")相当于
@Qualifiar+@Autowirde
注意:他是java包的.1.8以后需要单独导依赖不然可能获取到是Null//
// javax.annotation
// javax.annotation-api
// 1.3.2
//
@value("")普通数据类型注入
@scorp("")作用范围
@postConstruct初始化方法
@preDestroy使用在方法上标注该方法是Bean的销毁方法
@Lazy(布尔值)延时加载,true表示延时加载
Spring 新注解(配置注解)
@Configuration:代表标志该类是Spring的核心配置文件
@ComponentScan:用于组件包扫描的配置
@Bean(""):方法的返回值放在容器当中
@PropertySource:用于加载Propertise文件中的配置
@Improt 引入
#注解开发步骤
1.创建核心配置类
2.添加组件扫描
3.使用improt引入分配置类
Spring集成Junit
1.导入Spring集成Junit坐标Spring-text
2.使用@Runwith注解替换原来的运行期SpringJUnit4ClassRunner.class
3.使用@ContextConfiguration配置配置文件
4.使用@Autowird注入需要测试的对象
5.创建测试方法进行测试