I'm trying to load a properties file using Spring's @PropertySource annotation. The properties file is stored in a Wildfly 8 module. The error message that I'm getting is:
class path resource [campaigner.properties] cannot be opened because it does not exist
Here's the Java code, which is used by the application's services.
@Configuration
@PropertySource("classpath:campaigner.properties")
class ServiceConfigImpl implements ServiceConfig
{
@Autowired
private Environment env;
@Bean(name = "serviceConfig")
public ServiceConfig getServiceConfig()
{
return new ServiceConfigImpl(this.env);
}
}
Here's my jboss-deployment-structure.xml, which I'm putting in the META-INF directory of my .ear file.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.dr_dee_sw.campaigner" />
</dependencies>
</deployment>
</jboss-deployment-structure>
I've also put a MANIFEST.MF file in the META-INF directory
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
Here's my module file, which I've put in WILDFLY_HOME\modules\com\dr_dee_sw\campaigner\main directory, along with the campaigner.properties file
<module xmlns="urn:jboss:module:1.1" name="com.dr_dee_sw.campaigner">
<resources>
<resource-root path="."/>
</resources>
</module>
What am I missing?
This page led me to the answer: https://www.javacodegeeks.com/2012/09/jboss-as-7-classloading-explained.html. My jboss-deployment-structure.xml was wrong. I have an EJB-JAR file inside the EAR file and that needs to be the focus of that file. So, I had to switch from using <deployment> to <sub-deployment> as shown below.
<jboss-deployment-structure>
<sub-deployment name="campaigner-service.jar">
<dependencies>
<module name="com.dr_dee_sw.campaigner" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>