Ng *_*rma 1 java spring spring-boot microservices spring-cloud-config
问题:如何获取位置https://github.com/TEK-Leads/Config-Properties.git中的数据
当我尝试运行此应用程序时,它不显示任何结果,它只显示默认的传递结果(请参阅MessageController)。或显示此类消息的 ConfigClient 端日志。
无法找到 PropertySource:“http://localhost:8888/application/default”的 GET 请求发生 I/O 错误:连接被拒绝;嵌套异常是 java.net.ConnectException: 连接被拒绝
当将配置服务器端application.yml文件更改为bootstrap.yml时,抛出下面的异常时。
If you are using the git profile, you need to set a Git URI in your configuration. If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.
Run Code Online (Sandbox Code Playgroud)
配置服务器部分
Pom.xml
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.3</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.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<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>
Run Code Online (Sandbox Code Playgroud)
应用程序.yml
server:
port: 9090
spring:
cloud:
config:
server:
git:
uri: https://github.com/TEK-Leads/Config-Properties.git
clone-on-start: true
bootstrap: true
enabled: true
application:
name: Config-Server
management:
security:
enabled: false
Run Code Online (Sandbox Code Playgroud)
配置服务器应用程序类
package com.ramgovindhare.configserverapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class ConfigServerAppApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerAppApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
配置客户端部分
Pom.xml
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.3</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-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
Run Code Online (Sandbox Code Playgroud)
应用程序.yml
spring:
application:
name: client-config
cloud:
config:
uri: http://localhost:9090
config:
activate:
on-profile:
active:prod
management:
security:
enabled:false
Run Code Online (Sandbox Code Playgroud)
ConfigClient.类
package com.ramgovindhare.configserverclientapp.contorller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RefreshScope
@RestController
public class MessageController {
@Value("${msg:Config Server is not working. Please check..}")
private String msg;
@GetMapping("/msg")
public String getMsg() {
return this.msg;
}
}
Run Code Online (Sandbox Code Playgroud)
尝试在文件中添加依赖pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12523 次 |
| 最近记录: |