Accesing spring boot's application.properties on weblogic 10.3.6

帅比萌擦擦* 提交于 2019-12-13 07:38:27

问题


I am trying to acces a value defined in application.properties in a following way:

@Value("${server.url}")
private String serverUrl;

It works on embedded tomcat, but when I upload it to Weblogic I get the following error:

Error creating bean with name 'authorizationServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'server.url' in value "${server.url}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'server.url' in value "${server.url}"

How can I make use of the application.properties file when hosting app on Weblogic server?


回答1:


I found that if you want to use external properties on weblogic 10.3.6 you need to put the file in desired location and use the follwing annotation for setting property source in configuration/startup class:

@PropertySource(value = { "file:/...domains/MYdomain/application.properties" })



回答2:


You should never place the application-XXX.properties files specific to an environment in the deployed component itself.

You should always externalize them outside it.

So, to solve your missing properties file problem, you have just to add the properties file(s) in a folder that you will add in the weblogic runtime classpath.

You can set the setDomainEnv.cmd/sh file of your domain and add the folder path in the CLASSPATH variable.

For example, in Weblogic (11, 12 and maybe other older versions but not sure), in setDomainEnv.cmd, you should find this lines :

set JAVA_OPTIONS=%JAVA_OPTIONS%

@REM SET THE CLASSPATH

Replace @REM SET THE CLASSPATH by

SET CLASSPATH = %CLASSPATH%;yourPropertiesFilesAbsolutePath


来源:https://stackoverflow.com/questions/43975472/accesing-spring-boots-application-properties-on-weblogic-10-3-6

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