Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将外部属性文件与Springs一起用作init.d服务_Java_Linux_Spring Boot_Service_Properties File - Fatal编程技术网

Java 将外部属性文件与Springs一起用作init.d服务

Java 将外部属性文件与Springs一起用作init.d服务,java,linux,spring-boot,service,properties-file,Java,Linux,Spring Boot,Service,Properties File,我试图使用Spring提供的方法将Spring引导应用程序作为init.dlinux服务运行。而该服务将使用成功运行 service vxmonitor start RUN_ARGS=--spring.config.location=/var/vxmonitor/config.properties 将不会加载外部属性文件。属性文件与jar文件位于同一文件夹中。如果我使用 java -jar monitor-0.0.1-SNAPSHOT.jar --spring.config.location=

我试图使用Spring提供的方法将Spring引导应用程序作为init.dlinux服务运行。而该服务将使用成功运行

service vxmonitor start RUN_ARGS=--spring.config.location=/var/vxmonitor/config.properties
将不会加载外部属性文件。属性文件与jar文件位于同一文件夹中。如果我使用

java -jar monitor-0.0.1-SNAPSHOT.jar --spring.config.location=config.properties
外部属性加载良好

我的问题是如何让Springs服务指向外部配置文件,如果可能的话,如何将外部配置文件的位置集成到服务本身中,这样就不需要指定RUN_ARGS。不确定哪些文件有助于解决此问题

config.properties

server.port=8099
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.valgoix</groupId>
<artifactId>monitor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>vlgx-monitoring-svc</name>
<description>Client side server monitoring web service</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.restdocs</groupId>
        <artifactId>spring-restdocs-mockmvc</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.2-1003-jdbc4</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

除了运行服务时,我会收到错误消息

Error: Invalid or corrupt jarfile /var/vxmonitor/vxmonitor.jar

写入日志文件。

您需要为
spring.config.location
使用如下文件URL:


-spring.config.location=file:///var/vxmonitor/config.properties

您需要为
spring.config.location
使用如下文件URL:


-spring.config.location=file:///var/vxmonitor/config.properties

…此页面将帮助您…@VelNaga我没有看到任何与init.d服务的外部配置相关的文档。正如我提到的,我能够在运行jar时指定外部配置。。。此页面将帮助您…@VelNaga我没有看到任何与init.d服务的外部配置相关的文档。正如我提到的,我能够在运行jar时指定外部配置。
arguments=(-Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS -jar "$jarfile" --spring.config.location=/var/vxmonitor/config.properties $RUN_ARGS "$@")
Error: Invalid or corrupt jarfile /var/vxmonitor/vxmonitor.jar