在jar中找不到属性文件 [英] The property file is not found when it's in a jar
问题描述
自从我在罐子中部署应用程序以来,我的属性文件出现了问题。当它只是在WEB-INF / classes目录中时,没有问题。我的问题仅出现在jars中的属性文件中。
I've got a problem with my property file since I deploy my application within jars. When it was just in the WEB-INF/classes directory, there was no problem. My problems occur only with properties files inside jars.
让我解释一下。我将简化我的代码。
Let me explain. I will simplify my code.
我的应用程序处理称为IPX的商务对象(知道它是什么没有用)
My application deals with buisiness objects called IPX (it's not useful to know what it is)
有一个名为IpxDaoImpl的DAO类,具有字符串属性,即SQL查询
There's a DAO class called IpxDaoImpl with string attributes, that are SQL queries
public class IpxDaoImpl implements IpxDao extends SimpleJdbcDaoSupport {
private String listAllIpxSql; // query for listing IPX in Database
public void listAllIpx() {
// Does a query in Database using the variable listAllIpxSql
// ...
}
public void setListAllIpxSql(String listAllIpxSql) {
this.listAllIpxSql = listAllIpxSql;
}
}
此类在配置xml文件中定义,称为appContext-dao.xml。它包含:
This class is defined in a config xml file, called appContext-dao.xml. It contains :
<bean id="ipxDao" class="com.IpxDaoImpl" parent="myGenericDao">
<property name="listAllIpxSql" value="${ipx.list}" />
</bean>
还有另一个配置xml文件,它告诉如何加载属性文件:appContext-commo-dao .xml。它包含:
There is another config xml file, that tells how to load the properties files : appContext-commo-dao.xml. It contains :
<context:property-placeholder location="classpath*:**/sql.properties" />
并且有一个适合查询IPX的sql.properties文件。它包含:
And there is a sql.properties file proper to queries about IPX. It contains :
ipx.list=SELECT * FROM IPX
现在,当我在WEB-INF / classs中部署应用程序时,一切都很好。但是我们有一个必须生成jar的集成环境。我上面提到的所有文件都在同一个jar中。然后,当我进行部署时,出现了以下错误:
无法解析占位符'ipx.list'
似乎找不到属性文件sql.properties。
Now, when I deploy my application in WEB-INF/classes, everything is fine. But we have an integration environement where we have to generate jars. All the files I've mentioned above are in the same jar. And then, when I deploy, I've got this error : Could not resolve placeholder 'ipx.list' It seems that the property file sql.properties is not found.
我尝试提取此属性文件,并将其放在具有适当文件夹的WEB-INF / classes目录中。现在可以使用了。
I've tried to extract this property file and put it in the WEB-INF/classes directory, with the proper folder. And now it works.
那么,我的代码有什么问题?它是安慰剂吗?
预先感谢。
So, what is wrong with my code? Is it the placeholer ? Thanks in advance.
Cedric
推荐答案
尝试使用 classpath:/sql.properties
引用自:
请注意, classpath *:与Ant样式的模式结合使用时,
只能在
模式启动之前与至少一个根目录可靠地一起工作,除非实际的目标文件位于文件
系统中。
Please note that "classpath*:" when combined with Ant-style patterns will only work reliably with at least one root directory before the pattern starts, unless the actual target files reside in the file system.
这篇关于在jar中找不到属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!