无法在 weblogic 中使用 springboot 加载外部属性文件 [英] Not able to load external properties files with springboot in weblogic

查看:47
本文介绍了无法在 weblogic 中使用 springboot 加载外部属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 tomcat 在 spring boot 中加载外部属性文件,它在将其放入 lib 文件夹时按预期工作,但尽管我将 application.properties 文件放在 lib 文件夹中,但我无法使用 weblogic 服务器加载.

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.

代码片段:

     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;
       }

    }

推荐答案

所以下面是加载外部属性文件的链接.

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

您共享的代码将在 tomcat 中工作,因为 lib 文件夹下是实际的类路径,因此它将在服务器启动时加载,但它不适用于 weblogic,因为 weblogic 类路径是用户域文件夹而不是 lib 文件夹.

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.

您能否尝试将 application.properties 文件放在用户域文件夹中,它应该可以工作.

Can you try to put application.properties file in user domain folder and it should work.

在 weblogic 中找到您的用户域路径并将应用程序放入.那里的文件.

Find your user domain path in weblogic and put app. files there.

以下是您可以找到您的 weblogic 用户域路径/类路径的代码:

Below is the code you can find your weblogic user domain path/classpath :

 String appDomianPath= System.getProperty("user.dir"); 
 System.out.println(appDomianPath);

这篇关于无法在 weblogic 中使用 springboot 加载外部属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆