Reputation: 190
I have a war package and wanted to include an external classpath:
in my controller:
I have this following code:
WebApplication class:
@SpringBootApplication
@PropertySource( "classpath:config.properties" )
public class WebApplication{
public static void main(String[] args){
SpringApplication.run(WebApplication.class, args);
}
}
Controller Class:
@Controller
@PropertySource( "classpath:config.properties" )
public class ApplicationController{
//doing some stuff here
}
my folder:
|-project
|-src |-main |-java |-com.mypage.temp |-WebApplication.java (main class) |-com.mypage.temp.controller |-ApplicationController (Controller) |-resources |- [some stuff & not putting my properties file here to include externally] |-deploy |-config.properties
However when I build
project.war
I put in a remote server (unix):
|project
|-bin |-project.war |-config |-config.properties
Something/something/something/bin/project.war Something/something/something/config/config.properties
run command:
java -jar -Dclasspath=/something/something/something/config/config.properties project.war
Error:
Failed to parse configuration class [com.mypage.temp.WebApplication];
nested exception is java.io.FileNotFoundException: class path resource
[config.properties] cannot be opened because it does not exist
2016-12-19 18:13:16.763 ERROR 21662 --- [ main]
o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to
parse configuration class [com.mypage.temp.WebApplication]; nested
exception is java.io.FileNotFoundException: class path resource
[config.properties] cannot be opened because it does not exist
Upvotes: 1
Views: 1312
Reputation: 131456
From the official documentation, Spring Boot relies on the spring.config.location
Spring Boot property to specify the location of the environment properties file.
You may provide it in the command line.
You can also refer to an explicit location using the spring.config.location environment property (comma-separated list of directory locations, or file paths).
$ java -jar myproject.jar --spring.config.name=myproject or
$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
So, try that :
java -jar project.war --spring.config.location=classpath:/something/something/something/config/config.properties
Upvotes: 1