1. spring 开发中单元测试时的初始化参数(加载日志配置文件、加载 spring 配置文件)
- 代码片段
DOMConfigurator.configure ("./files/log4j.xml"); // 加载日志文件
ApplicationContext contextConfig = new FileSystemXmlApplicationContext("./files/base_beans.spring.xml"); // 加载 spring 文件
PrototypeEntity prototype = contextConfig.getBean("prototypeEntity", PrototypeEntity.class); // 通过 bean id 获取对象
// bean 的注入、scope="prototype" 表示多例
<bean id="prototypeEntity" scope="prototype" class="com.aiden.demo.base.entites.PrototypeEntity">
<property name="testService" ref="testService"/>
</bean>
- 依赖 jar 包
- 测试案例截图