spring cloud 之config配置

Spring Cloud Config服务器

服务器为外部配置(名称值对或等效的YAML内容)提供了基于资源的HTTP。服务器可以使用@EnableConfigServer注释轻松嵌入到Spring Boot应用程序中。所以这个应用程序是一个配置服务器:

ConfigServer.java
@SpringBootApplication
@EnableConfigServer
public class ConfigServer {
  public static void main(String[] args) {
    SpringApplication.run(ConfigServer.class, args);
  }
}

 

首先搭建springboot项目  

在resources下面创建2个.yml配置文件

1.

server:
port: 8888
spring:
cloud:
config:
server:
encrypt:
enabled: false
git:
uri:  这里填写git地址
searchPaths:  gir的目录地址   如项目是8080:admin   就填写admin多个用,号
username: git的username
password: gir的pass

 

在git地址上创建***.yml文件 的配置  比如mysql的 redis的配置 和searchPaths地址对应

server:
port: 13880
servlet:
context-path: /admin
spring:
application:
name: admin
profiles:
active: default
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql:mysql连接地址
password: 账号
jpa:
hibernate:
ddl-auto: update
show-sql: true
database: mysql
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
redis:
host: 192.168.0.77
swagger:
enabled: true
eureka:
instance:
prefer-ip-address: true
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: eureka地址 用于发布和注册服务的  
security:
oauth2:
resource:
user-info-uri: 用于安全框架地址

2.

spring:
application:
name: configserver
encrypt:
key: mykey
#debug: true

 

pom.xml: 配置sprongboot和springCloud相关jar包

 

<name>confsvr</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.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>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</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>

posted @ 2018-09-05 17:37  全栈冲鸭!  阅读(223)  评论(0编辑  收藏  举报