spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.96k stars 1.29k forks source link

SpringCloudConfig run error when "java -jar myconfigserver.jar" #1501

Closed oaHeZgnoS closed 5 years ago

oaHeZgnoS commented 5 years ago

My Env: SpringBoot2.1.3, SpringCloud Grenwich, Jdk 1.8, Native repository(I use my local disk as my config repo rather than git or svn..)

It runs ok when I use Eclipse to start directly.However, when I use "java -jar myconfigserver.jar", Error occurred: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'multipleJGitEnvironmentProperties': Could not bind properties to 'MultipleJGitEnvironmentProperties' : prefix=spring.cloud.config.server.git, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.config.server.git' to org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties

Waiting for your answer.

spencergibb commented 5 years ago

Please add your configuration

oaHeZgnoS commented 5 years ago

Hey, guy, I tried again on my company's PC and tried on my house's PC. And those project codes are same(copy). Unexpectedly, it runs successfully on my house's PC. And it runs unsuccessfully on my company's PC.

My env on my house's PC: jdk 1.8(same with company's PC), Eclipse Mars2(differ from company's PC Mars1), Maven 3.xx(I forgot it. Company's Maven is 3.6.0).

And I compared house's jar with company's jar. I discovered that company's jar lacks 3 jars(JavaEWAH-1.1.6.jar, jsch-0.1.54.jar, jzlib-1.1.1.jar). Then I check my pom.xml, those scope are compile. However, those three haven't been packaged in company's jar. Maybe this is my env's problem rather than a bug of SpringCloudConfig...

My 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath/>
</parent>
<groupId>com.cjia</groupId>
<artifactId>spider-config</artifactId>
<version>1.0.0</version>
<name>config</name>
<description>SpringCloudConfig for spider</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- log4j -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
        <version>1.3.8.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <!-- spring-security -->
    <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency> -->
    <!-- 消息总线 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-kafka</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Greenwich.SR2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

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

`

My application.properties: `spring.application.name=spider-config server.port=7001

配置服务注册中心

eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka/

本地文件系统

本地文件系统的存储方式来保存配置信息,设置native,会默认从应用的src/main/resource目录下搜索配置文件

spring.profiles.active=native

指定具体的配置文件位置

spring.cloud.config.server.native.searchLocations=E:/codes_svn/spider_trunk/spider-config/src/main/resources/properties

对配置中心的访问增加安全验证,同时需要在config客户端增加验证配置

若开启安全认证,访问/bus-refresh报401或403,疑似bug

spring.security.user.name=cjiaspider

spring.security.user.password=spider_123

management.security.enabled=false

Spring Cloud Bus配置

spring.kafka.bootstrap-servers=10.1.4.17:9092

开启mq的日志追踪

spring.cloud.bus.trace.enabled=true

通过总线refresh

management.endpoints.web.exposure.include=bus-refresh `

Finally, maybe I can forcely and directly add those three dependences to resolve my problem. But I hope to find its root cause.

oaHeZgnoS commented 5 years ago

Add another point, I could run successfully on my company's PC and run in Eclipse. If I try it by 'java -jar xx.jar', it's always lose.

oaHeZgnoS commented 5 years ago

I have discovered the root cause by using 'mvn -X'. I delete sth(download Incomplete bad pom) in mvn repo. Then those three jars are packaged.

This is not a bug. Please close it.