Spring Cloud Config
程序员文章站
2022-07-14 22:45:14
...
pom.xml
<!-- spring-cloud-config-server-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
application.yml
server:
port: 6809
eureka:
client:
serviceUrl:
defaultZone: http://localhost:6888/eureka/
spring:
application:
name: spring-cloud-config-server
cloud:
config:
server:
git:
uri: https://gitee.com/mingshine/SpringCloud-Config/ #GitHub上面的git仓库名字
# search-paths: SpringCloud-Config
SpringCloudConfigServerApplication.java
package com.mingshine.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class SpringCloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigServerApplication.class, args);
}
}
pom.xml
<!-- spring-cloud-config-client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
application.yml
server:
port: 6810
eureka:
client:
serviceUrl:
defaultZone: http://localhost:6888/eureka/
spring:
application:
name: spring-cloud-config-client
bootstrap.yml
spring:
cloud:
config:
label: master
uri: http://localhost:6809/ #本微服务启动后先去找3344号服务,通过SpringCloudConfig获取GitHub的服务地址
SpringCloudConfigClientApplication.java
package com.mingshine.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class SpringCloudConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigClientApplication.class, args);
}
}
ClientController.java
package com.mingshine.cloud;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ClientController {
@Value("${test}")
String test;
@RequestMapping(value = "/test")
public String test() {
return test;
}
}
上一篇: 几种任务调度的 Java 实现方法与比较
下一篇: 任务调度Quartz和spring整合
推荐阅读
-
phpmyadmin config.inc.php配置示例
-
C# 添加文本、图片到PDF文档(基于Spire.Cloud.PDF.SDK)
-
java 调用Spring接口上传文件及其他参数填充
-
Spring Cloud开发人员如何解决服务冲突和实例乱窜?(IP实现方案)
-
Spring源码解析之ConfigurableApplicationContext
-
spring data jpa碰到的坑
-
IIS配置文件的XML格式不正确 applicationHost.config崩溃
-
Apache shiro的简单介绍与使用教程(与spring整合使用)
-
你知道@RequestMapping的name属性有什么用吗?【享学Spring MVC】
-
Spring Cloud Gateway的动态路由怎样做?集成Nacos实现很简单