无法在weblogic中使用springboot加载外部属性文件
Not able to load external properties files with springboot in weblogic
我正在尝试在 spring 引导中加载外部属性文件 tomcat 它在将其放入 lib 文件夹时按预期工作但我无法加载 weblogic 服务器虽然我将 application.properties 文件放入 lib 文件夹。
代码片段:
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;
}
}
所以下面是 link 加载外部属性文件。
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
您共享的代码将在 tomcat 中运行,因为 lib 文件夹下是实际的类路径,因此它将在服务器启动时加载,但它不适用于 weblogic,因为 weblogic 类路径是用户域文件夹,并且不是 lib 文件夹。
您可以尝试将 application.properties 文件放在用户域文件夹中吗,它应该可以工作。
在weblogic中找到你的用户域路径,把app.那里的文件。
下面是您可以找到您的 weblogic 用户域的代码 path/classpath :
String appDomianPath= System.getProperty("user.dir");
System.out.println(appDomianPath);
我正在尝试在 spring 引导中加载外部属性文件 tomcat 它在将其放入 lib 文件夹时按预期工作但我无法加载 weblogic 服务器虽然我将 application.properties 文件放入 lib 文件夹。
代码片段:
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;
}
}
所以下面是 link 加载外部属性文件。
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
您共享的代码将在 tomcat 中运行,因为 lib 文件夹下是实际的类路径,因此它将在服务器启动时加载,但它不适用于 weblogic,因为 weblogic 类路径是用户域文件夹,并且不是 lib 文件夹。
您可以尝试将 application.properties 文件放在用户域文件夹中吗,它应该可以工作。
在weblogic中找到你的用户域路径,把app.那里的文件。
下面是您可以找到您的 weblogic 用户域的代码 path/classpath :
String appDomianPath= System.getProperty("user.dir");
System.out.println(appDomianPath);