Spring Cloud Build Manual (2)--spring Cloud Config

Source: Internet
Author: User
Tags lua

※ After the DALSTON.SR2 version, the encryption is not normal, if you must use this feature, you need to downgrade to SR1 or Camden SR7.

1, first need to create a config-server project, as a configuration Center server, used to connect with git, svn or the local warehouse, get the configuration file from the warehouse

The ①config-server project Pom file needs to add the following dependencies:

<Dependency><GroupId>org.springframework.cloud</GroupId><Artifactid>spring-cloud-config-server</Artifactid></Dependency><Dependency><groupid> Org.springframework.cloud</groupid> <artifactId< Span class= "Hljs-tag" >>spring-cloud-starter-security</artifactid></ dependency>          

② adding annotations to the Spring boot entry class to enable the Configuration Center server

@EnableConfigServer

③ also use application-peer1.properties and application-peer2.properties to configure

spring.profiles.active=peer1server.port=8001
spring.profiles.active=peer2server.port=8002

To configure the public configuration in Application.properties:

spring.application.name=config-server-service#disable security when testingmanagement.security.enabled=falsesecurity.user.name=adminsecurity.user.password=taoge1gbspring.cloud.config.server.git.uri=https://github.com/spring-cloud.gitspring.cloud.config.server.git.searchPaths=spring-cloud-config-repospring.cloud.config.server.git.username=taogespring.cloud.config.server.git.password=taoge1gbeureka.client.serviceUrl.defaultZone=http://admin:[email protected]:8361/eureka,http://admin:[email protected]:8362/eureka

④ Execute the following startup commands to initiate activation Peer1 and Peer2, respectively:

java -jar config-server-1.0.0.jar --spring.profiles.active=peer1java -jar config-server-1.0.0.jar --spring.profiles.active=peer2

2. For config-client, the following configuration is required:

① first to add config-client dependencies in the Pom file:

<Dependency><groupid> Org.springframework.cloud</groupid> <artifactId< Span class= "Hljs-tag" >>spring-cloud-starter-config</artifactid></ dependency>          

② configuring Config-server information in Bootstrap.properties:

eureka.client.serviceUrl.defaultZone=http://admin:[email protected]:8361/eureka,http://admin:[email protected]:8362/eurekaspring.cloud.config.profile=devspring.cloud.config.name=testspring.cloud.config.label=developspring.cloud.config.username=adminspring.cloud.config.password=taoge1gbspring.cloud.config.discovery.enabled=truespring.cloud.config.discovery.serviceId=config-server-service

※ must be configured in Bootstrap.properties, so that the configuration will take effect when the program starts.

③ Turn on Failure retry (optional), you need to add dependencies in the Pom file:

<Dependency><GroupId>org.springframework.retry</GroupId><Artifactid>spring-retry</Artifactid></Dependency><Dependency><groupid> Org.springframework.boot</groupid> <artifactId< Span class= "Hljs-tag" >>spring-boot-starter-aop</artifactid> </dependency>          

Then turn on the retry feature in the bootstrap.properties configuration file:

spring.cloud.config.failFast=true

3, if you want to enable the encryption and decryption of the password in the configuration file, Spring Cloud config requires encryption extension Unlimited strength limit, so you need to download the JCE, replace the original JDK encryption expansion pack

JDK 7:

http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

JDK 8:

http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

After the download is complete, copy the Local_policy.jar and Us_export_policy.jar and overwrite it with the $java_home/jre/lib/security.

4. Problems that may be encountered:

① Use Curl localhost:8888/encrypt-d mysecret to get encrypted ciphertext, return 401,{"timestamp": 1517811624176, "status": 401, "Error": " Unauthorized "," message ":" Full authentication are required to access this resource "," path ":"/encrypt "}

Cause: Because Spring Cloud config server prints the password on the console at startup, you need to bring the default user name and password when you access it.

WORKAROUND: It is recommended to add the specified user name password when configuring Application.properties:

security.user.name=adminsecurity.user.password=taoge1gb

When accessing, use Curl http://admin:taoge1gb@localhost:8888/encrypt-d MySecret

or turn off validation

management.security.enabled=falsesecurity.basic.enabled=false

② when accessing Curl http://admin:taoge1gb@localhost:8888/encrypt-d MySecret, return 404,{"description": "No key is installed for Encryption service "," status ":" No_key "}

Cause: The key used when encryption is not set.

Workaround: When configuring Application.properties, add the configuration of key:

encrypt.key=sisterred

※ After the DALSTON.SR2 version, the encryption is not normal, if you must use this feature, you need to downgrade to SR1 or Camden SR7.

Reference: https://github.com/spring-cloud/spring-cloud-config/issues/767

③ configuration of the Git repository cannot be cloned and checked out

Cause: Configuring the path to the Spring.cloud.config.server.git.uri must be a URL specified to the. git, which can be accessed through the browser, and the path configured by the test is correct.

The path after the. Git, then, needs to be configured in Spring.cloud.config.server.git.searchPaths.

Workaround: Configure the form as follows

spring.cloud.config.server.git.uri=https://github.com/spring-cloud.gitspring.cloud.config.server.git.searchPaths=spring-cloud-config-repo

④ after updating configuration, send/bus/refresh request, return 401

Send Curl-x POST Http://localhost:8088/bus/refresh and return the following:

{"Timestamp": 1517974621306, "status": 401, "error": "Unauthorized", "message": "Full authentication are required to access This resource. "," path ":"/bus/refresh "}

Cause: Because the Spring Cloud Config client prints the password on the console at startup, the default user name and password are required for access.

WORKAROUND: It is recommended to add the specified user name password when configuring Application.properties:

security.user.name=adminsecurity.user.password=taoge1gb

When accessing, use Curl-x POST Http://admin:taoge1gb@localhost:8088/bus/refresh

or turn off validation

management.security.enabled=falsesecurity.basic.enabled=false

Spring Cloud Build Manual (2)--spring Cloud Config

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.