在外部文件夹war文件命令springjava中运行classpath

在外部文件夹war文件命令springjava中运行classpath,java,spring,spring-boot,properties-file,Java,Spring,Spring Boot,Properties File,我有一个war包,希望包含一个外部类路径: 在我的控制器中: 我有以下代码: WebApplication类: @SpringBootApplication @PropertySource( "classpath:config.properties" ) public class WebApplication{ public static void main(String[] args){ SpringApplication.run(WebApplication.clas

我有一个war包,希望包含一个外部类路径:

在我的控制器中:

我有以下代码:

WebApplication类:

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

   public static void main(String[] args){
        SpringApplication.run(WebApplication.class, args);
   }
}
@Controller
@PropertySource( "classpath:config.properties" )
public class ApplicationController{

     //doing some stuff here

}
控制器类:

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

   public static void main(String[] args){
        SpringApplication.run(WebApplication.class, args);
   }
}
@Controller
@PropertySource( "classpath:config.properties" )
public class ApplicationController{

     //doing some stuff here

}
我的文件夹:

|-计划

|-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
然而,当我建立

战争计划

我安装了一个远程服务器(unix):

|计划

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

运行命令:

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

错误:

 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
从中,Spring引导依赖于
Spring.config.location
Spring引导属性来指定环境属性文件的位置
您可以在命令行中提供它

您还可以使用 spring.config.location环境属性(以逗号分隔的 目录位置或文件路径)

$java-jar myproject.jar--spring.config.name=myproject或

$java-jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

因此,尝试一下:

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

哪个是你的操作系统?Unix是我的操作系统。这个命令在我的机器上工作。你确定这条路吗?尝试不使用类路径:
java-jar project.war--spring.config.location=/something/something/something/config/config.properties