junit测试,使用classpath和file 加载文件的区别
用junit测试发现一个问题,怎么加载配置文件?一直都出现这样的错误
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@2d2bf892] to prepare test instance [com.zdwl.test.WriteData@21cc5069]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.zdwl.test.WriteData': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zdwl.dao.impl.JdbcDaoImpl com.zdwl.test.WriteData.jdbcDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zdwl.dao.impl.JdbcDaoImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}\
以前都是用classpath加载配置文件。
例如:
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations={"classpath:spring-dao-test.xml"})
public void TestA{
}
然后发现一直不能将dao接口注入到impl实现类中,其实本质原因还是配置文件没有加载对。
一直在纠结中..............
然后又用
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations={"file:WEB-INFO/spring-dao-test.xml"})
还是不对。
又用classpath*:/spring-dao-test.xml 加载 。。。。还也不能加载。。。我也晕了,咋整都不行呢?
然后又在其他项目里发现测试用的是:file:/spring-dao-test.xml;我就思考为什么用file加载,而不是classpath去加载配置文件。
最终。。。。
file:加载非编译类的文件系统,即:作为 URL 从文件系统中加载。
classpath:加载编译的class文件系统,即:从classpath中加载。
由于我的配置文件是非编译类配置文件。所以我选择用file:加载配置文件。写全配置文件的绝对路径。
以下是加载配置文件的classpath,file的表格对比:
| 前缀 | 例子 | 说明 |
|---|---|---|
|
classpath: |
|
从classpath中加载。 |
|
file: |
|
作为 |
|
http: |
|
作为 |
|
(none) |
|
根据 |
|
|
||
junit测试,使用classpath和file 加载文件的区别的更多相关文章
- 服务 在初始化安装时发生异常:System.IO.FileNotFoundException: "file:///D:\testService"未能加载文件或程序集。系统找不到指定文件。
@echo.@if exist "%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" goto INSTALL ...
- winform水晶报表编译错误,未能加载文件或程序集"file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framewor "
未能加载文件或程序集“file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Commo ...
- 未能加载文件或程序集“file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0
未能加载文件或程序集"file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framewor ...
- 未能加载文件或程序集“file:///D:/Program Files (x86)/ArcGIS/DeveloperKit10.0/DotNet/ESRI.ArcGIS.3DAnalyst.dll”或它的某一个依赖项。试图加载格式不正确的程序。 行 129,位置 5。
能加载文件或程序集“file:///C:/Program Files (x86)/ArcGIS/DeveloperKit10.0/DotNet/ESRI.ArcGIS.ADF.Local.dll”或它 ...
- resx文件在X64位编译,提示“未能加载文件或程序集”的问题?
原文:resx文件在X64位编译,提示"未能加载文件或程序集"的问题? resx文件在X64位编译,提示"未能加载文件或程序集"的问题? 解答: 错误现象如下 ...
- 未能加载文件或程序集“System.Data.SQLite.DLL”或它的某一个依赖项
今天在部署code到测试环境的时候 出现了未能加载文件或程序集"System.Data.SQLite.DLL"或它的某一个依赖项 这个错误,其实错误的的原因有很多,1.典型的是是版 ...
- RDLC报表 在WinForm里运行出现 未能加载文件或程序集microsoft.reportviewer.winforms
做一下记录顺便帮助一下遇到问题的朋友. 做RDLC报表在WinForm运行,在VS里面调试引用了“Microsoft.ReportViewer.Common.dll”和“Microsoft.Repor ...
- 未能加载文件或程序集“DeveloperKit10.1/DotNet/ESRI.ArcGIS.ADF.Local.或它的某一个依赖项
使用VS2010进行ArcGIS Engine 10.1进行开发过程中,出现: 错误 1 未能加载文件或程序集“file:///D:/ArcGIS/DeveloperKit10.0/DotNet/ES ...
- 错误处理:加载文件或程序集“ICSharpCode.SharpZipLib”
解决方案:如果你的程序是2.0的,则删除 C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/中的所有的文件 如果是4.0的,删除C:/WINDOWS/Micr ...
随机推荐
- java的动态代理机制详解
在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们不但要知道怎么通过AOP来满足的 ...
- Gulp常用前端流程自动化配置
前言 近期的项目全部由Grunt + LESS 转向改用Gulp + SASS 进行前端开发,也就奔着Gulp那比较好用的自定义函数而来的. 一.package.json文件配置如下: { " ...
- [DataMining]WEEK1 - text-retrieval and search engine
What does a computer have to do in order to understand a natural language sentence? What is ambiguit ...
- JavaScript对象状态
有限状态机(Finite-state machine)是一个非常有用的模型,可以模拟世界上大部分事物. 简单说,它有三个特征: * 状态总数(state)是有限的. * 任一时刻,只处在一种状态之中. ...
- 使用sublime text 开发node.js
http://blog.csdn.net/jwkfreedom/article/details/8450005 本机环境: windows7 64位 1. 下载安装sublime text, 不用注册 ...
- myEclipse Could not create the view: An unexpected exception was thrown.
myEclipse 非正常关闭,打开后 service Explorer or Package Explorer 视图显示不出来.报“Could not create the view: An une ...
- iOS判断对象相等 重写isEqual、isEqualToClass、hash
相等的概念是探究哲学和数学的核心,并且对道德.公正和公共政策的问题有着深远的影响. 从一个经验主义者的角度来看,两个物体不能依据一些观测标准中分辨出来,它们就是相等的.在人文方面,平等主义者认为相等意 ...
- linux shell中不显示路径了,显示为-bash-4.1#的两种解决办法
出现这个问题的原因是因为没有配置.bash_profile的问题,或者是我们不小心清空或删除了.bash_profile文件. 办法一:修改 ~/.bash_profile文件 步骤如下: vim ~ ...
- JQM开发Tips
1.radio Button 点击后有时候有高亮样式,有时候没有 解决方案: $("#task_form label").click(function () { $("# ...
- C++ 小知识积累
(1)setw和setfill函数 #include<iomanip> 代码: #include<iostream> #include<iomanip> using ...