在外部文件夹战争文件命令弹簧java中运行类路径



我有一个战争包,想包括一个外部类路径:

在我的控制器中:

我有以下代码:

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
}

我的文件夹:

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

但是,当我构建

project.war

我放入远程服务器(UNIX):

|项目

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

某物/事物/某物/bin/project.war 某物/事物/事物/config/config.properties

运行命令:

java -jar -dclasspath =/sosings/sosings/sosings/sosings/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 Boot依靠spring.config.location Spring Boot属性来指定环境属性文件的位置。
您可以在命令行中提供。

您还可以使用该位置参考 spring.config.Location Envorymon属性(逗号分隔的列表 目录位置或文件路径)。

$ 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 

最新更新