Junit手动/自动加载spring配置文件
来源:互联网 发布:mysql between 编辑:程序博客网 时间:2024/06/06 03:42
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 { ...
阅读全文
0 0
- Junit手动/自动加载spring配置文件
- spring boot 中手动加载配置文件
- 请慎用spring-ClassPathXmlApplicationContext手动加载spring配置文件
- 请慎用spring-ClassPathXmlApplicationContext手动加载spring配置文件
- JUnit加载properties配置文件
- Spring中自动加载Hibernate配置文件
- Spring Xml配置文件自动加载properties文件
- java logback手动加载配置文件
- java logback手动加载配置文件
- 配置文件自动重新加载
- spring junit解决延迟加载
- JUnit 中加载spring 配置
- Spring配置文件加载外部配置文件
- spring配置文件加载
- spring多配置文件加载
- spring 加载配置文件
- Spring配置文件加载流程
- spring加载xml配置文件
- 中国程序员如何升职加薪,也许我们该学学印度人
- JDBC之事务处理
- Linux常用命令
- javascript之闭包的理解
- 面试问题a+=b 和a=a+b的区别
- Junit手动/自动加载spring配置文件
- Java利用ThreadLocal计算当前线程运行时间
- PHPtime与日期date之间
- Mysql Connection already closed
- Qt Creator 搭配Git 版本控制
- matlab函数ifft
- iOS KeyChain使用
- 浅谈设计模式
- vue props 拿不到值的解决方案