Not able to load external properties files with springboot in weblogic

泪湿孤枕 提交于 2019-12-06 11:24:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!