I'm trying to read a configuration files which I put under /WEB-INF/config folder. The reason is that the Jetty Maven plugin does not support resource filtering. Can some one please explain me how to do that using Spring Java configuration feature ?
I know that <context: property-placeholder ... />
should work, but i dont want to use XML.
application dirs
├───META-INF
└───WEB-INF
├───classes
├───config
├───i18n
├───lib
├───pages
└───resources
property sources configuration
@Configuration
@EnableWebMvc
@PropertySources({
@PropertySource("log4j.properties"),
@PropertySource("general.properties") }
)
public class ApplicationContext extends WebMvcConfigurerAdapter {
@Autowired
ServletContext servletContext;
@Bean
public PropertyPlaceholderConfigurer properties() {
PropertyPlaceholderConfigurer propertySources = new PropertyPlaceholderConfigurer();
Resource[] resources = new ServletContextResource[] {
new ServletContextResource(servletContext, "WEB-INF/config/log4j.properties"),
new ServletContextResource(servletContext, "WEB-INF/config/general.properties")
};
propertySources.setLocations(resources);
propertySources.setIgnoreUnresolvablePlaceholders(true);
return propertySources;
}
}
exception:
java.lang.IllegalArgumentException: Cannot resolve ServletContextResource without ServletContext