问题
I am trying to load the external properties file in spring boot with tomcat it is working as expected while putting it in lib folder but I am not able to load with weblogic server though I put application.properties file in lib folder.
Code snippet :
public class ApplicationFilesInitializer extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class).properties(getProperties());
}
static Properties getProperties() {
Properties props = new Properties();
props.put("spring.config.location","classpath:{appname}-application.properties");
return props;
}
}
回答1:
So Below is the link to load external properties file.
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
The code which you share will work in tomcat as under lib folder is the actual classpath so it will load while server start up, but it will not work with weblogic as weblogic classpath is user domain folder and not the lib folder.
Can you try to put application.properties file in user domain folder and it should work.
Find your user domain path in weblogic and put app. files there.
Below is the code you can find your weblogic user domain path/classpath :
String appDomianPath= System.getProperty("user.dir");
System.out.println(appDomianPath);
来源:https://stackoverflow.com/questions/41352916/not-able-to-load-external-properties-files-with-springboot-in-weblogic