问题
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