2016-12-19 5 views
1

ich einen Krieg Paket haben und wollte einen externen Classpath enthalten:Lauf Classpath in externen Ordner WAR-Datei Befehl Frühling java

in meinem Controller:

Ich habe diesen Code ein:

WebApplication Klasse:

@SpringBootApplication 
@PropertySource("classpath:config.properties") 
public class WebApplication{ 

    public static void main(String[] args){ 
     SpringApplication.run(WebApplication.class, args); 
    } 
} 

Controller-Klasse:

@Controller 
@PropertySource("classpath:config.properties") 
public class ApplicationController{ 

    //doing some stuff here 

} 

mein Ordner:

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

Allerdings, wenn ich

project.war

Ich habe in einem Remote-Server (Unix) bauen:

|project

|-bin 
    |-project.war 
    |-config 
    |-config.properties 

Something/something/something/bin/project.war Something/something/something/config/config.properties

Startbefehl:

java -jar -Dclasspath=/something/something/something/config/config.properties project.war

Fehler:

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 

Antwort

1

Vom official documentation, Frühling-Boot verlässt sich auf die spring.config.location Frühlings-Boot-Eigenschaft, um die Lage der Umwelt Eigenschaften Datei angeben.
Sie können es in der Befehlszeile angeben.

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

Also, versuchen Sie das:

java -jar project.war --spring.config.location=classpath:/something/something/something/config/config.properties 
+0

es nicht – isme

+0

funktioniert Welches ist Ihr Betriebssystem ist? – davidxxx

+0

Unix ist mein Betriebssystem – isme