Junit手动/自动加载spring配置文件
2017-09-26 17:56
423 查看
Junit手动加载配置文件
配置文件在classpath下和WEB-INF下两种情况的加载:ApplicationContext context = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml"); new ClassPathXmlApplicationContext("applicationContext.xml");// 从classpath中加载 new FileSystemXmlApplicationContext("classpath:地址");// 没有classpath表示当前 eg: // 加载spring与数据库配置的部分得到DataSource // ==>位置是resources下面的 ApplicationContext context = new ClassPathXmlApplicationContext("spring/spring-config.xml"); DataSource ds = (DataSource) context.getBean("dataSource"); Connection connection = ds.getConnection();
Junit自动加载配置文件
@org.springframework.test.context.ContextConfiguration(locations={"file:WebRoot/WEB-INF/applicationContext.xml"}) @org.springframework.test.context.ContextConfiguration(locations={"classpath:applicationContext.xml"}) eg: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:spring/*"}) public class CreateDBTest { ... // 多个配置文件 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath*:/spring1.xml", "classpath*:/spring2.xml" }) public class CreateDBTest { ...
相关文章推荐
- Junit手动/自动加载spring配置文件
- SqlMapConfig.xml --- 在spring配置文件中自动加载的mybatis文件
- SqlMapConfig.xml---在spring配置文件中自动加载的mybatis文件
- 请慎用spring-ClassPathXmlApplicationContext手动加载spring配置文件
- Spring中自动加载Hibernate配置文件
- junit测试用例加载spring配置文件
- Spring下的单元测试(JUnit)--加载配置文件
- ssh整合思想初步 struts2与Spring的整合 struts2-spring-plugin-2.3.4.1.jar下载地址 自动加载Spring中的XML配置文件 Struts2下载地址
- spring-自动加载配置文件\使用属性文件注入
- 请慎用spring-ClassPathXmlApplicationContext手动加载spring配置文件
- spring 配置文件无法加载,junit找不到xml配置文件java.lang.IllegalStateException: Failed to load ApplicationContext
- Spring 配置文件xxxx.xml文件中scheme约束exlipse自动加载不了的解决
- 通过web.xml文件自动启动spring容器加载对应的配置文件
- spring boot 中手动加载配置文件
- spring-自动加载配置文件\使用属性文件注入
- junit进行测试加载多个spring配置文件
- Spring Web项目spring配置文件随服务器启动时自动加载
- spring-自动加载配置文件\使用属性文件注入
- log4j配置文件详解及手动加载的方式
- Spring的 classpath 通配符加载配置文件