1. Problem description
the project is built using maven, and the configuration files are placed under src/main/resources.
because there are frequent changes to the web.xml configuration during project development, the project manager uses variables (sso.path) to specify external profiles, each using a local profile.
but the problem is that when I want to switch to the configuration in the src/main/resources directory again, I don"t know what to say (you can comment it all, of course, but there are more changes).
if there is a subdirectory, it"s a good indication, such as classpath:/spring, but my configuration files are all in the root directory. I"ve tried classpath: classpath:/ and classpath://, in a mess, and it doesn"t seem to work.
ask for advice! Thanks!
2. The code is as follows
configuration in web.xml
<context-param>
<!-- -->
<param-name>sso.path</param-name>
<!-- src/main/resouces -->
<param-value>file:f:/config</param-value>
</context-param>
<listener>
<listener-class>cn.xx.xx.api.sso.listener.ConfigContextListener</listener-class>
</listener>
ConfigContextListener implementation
public class ConfigContextListener implements ServletContextListener{
@Override
public void contextInitialized(ServletContextEvent sce) {
String path = sce.getServletContext().getInitParameter("sso.path");
//
System.setProperty("sso.path", path);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
use: for example, in spring-redis.xml (and many configuration files use this variable)
<context:property-placeholder location="${sso.path}/spring/redis.properties"
ignore-unresolvable="true" />