我正在尝试使用Spring的@PropertySource注释加载属性文件。属性文件存储在Wildfly 8模块中。我得到的错误信息是:
class path resource [campaigner.properties] cannot be opened because it does not exist
以下是应用程序服务所使用的Java代码。
@Configuration
@PropertySource("classpath:campaigner.properties")
class ServiceConfigImpl implements ServiceConfig
{
@Autowired
private Environment env;
@Bean(name = "serviceConfig")
public ServiceConfig getServiceConfig()
{
return new ServiceConfigImpl(this.env);
}
}
这是我的jboss-deployment-structure.xml,我将它放在.ear文件的META-INF目录中。
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.dr_dee_sw.campaigner" />
</dependencies>
</deployment>
</jboss-deployment-structure>
我还放了一个MANIFEST。META-INF目录中的MF文件
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_71-b14 (Oracle Corporation)
Dependencies: com.dr_dee_sw.campaigner
这是我的模块文件,我把它放在WILDFLY_HOME\modules\com\dr_de_sw\activator\main目录中,还有activator.properties文件
<module xmlns="urn:jboss:module:1.1" name="com.dr_dee_sw.campaigner">
<resources>
<resource-root path="."/>
</resources>
</module>
我错过了什么?
这一页让我找到了答案:https://www.javacodegeeks.com/2012/09/jboss-as-7-classloading-explained.html.我的jboss-deployment-structure.xml是错误的。我在EAR文件中有一个EJB-JAR文件,它需要成为该文件的焦点。所以,我不得不从使用<deployment>到<子部署>,如下所示。
<jboss-deployment-structure>
<sub-deployment name="campaigner-service.jar">
<dependencies>
<module name="com.dr_dee_sw.campaigner" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>