I could not load the db.properties located inside the jar (project.service.jar), which is referred by the war file (project-web.war). The output war has the jar inside WEB-INF/lib/project.service.jar. The services jar has the services and dao classes used by the web app. The jar is also used by the rest war which uses some of the services from the jar. When the war starts I could not load the db.properties located in the jar file of the services. The prop file has the datasource name to lookup in jndi.
war config
AppConfig.java
@Bean
public static PropertyPlaceholderConfigurer propertyConfigurer()
throws IOException {
PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
props.setLocations(new Resource[] { new ClassPathResource(
"application.properties") });
return props;
}
service.jar
@Component
@Configuration
//@ComponentScan(basePackages={ "com.mgage.mvoice" })
@PropertySource(value = { "classpath:db.properties" })
public class DatabaseConfig {
@Autowired
Environment environment;
private @Value(value = "${voice.datasource}") String dataSourceString;
@Bean
public DataSource getDataSource() {
JndiDataSourceLookup lookup = new JndiDataSourceLookup();
try {
DataSource dataSource = lookup.getDataSource(dataSourceString); //this always is null
return dataSource;
} catch (DataSourceLookupFailureException e) {
return null;
}
}
@Bean
public PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
should AppConfig.java import the DataSourceConfig.java, I tried but I still get the Environment null. Am I missing anything? Is it right to separate the services as jar file to make them available for REST, Web app and Reports applications? Or is it advisable to have a single war with all services, rest, reports classes?