在我的Spring Cloud Config yaml文件中,我可以使用序列吗?我想将yaml序列映射到Java ArrayList并注入值.
一个例子就是这样的.
YAML文件:
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
Run Code Online (Sandbox Code Playgroud)
Java Spring Bean:
@Value("${american}")
List<String> american;
Run Code Online (Sandbox Code Playgroud) 我很好奇我有什么选择来保证服务连接(注册和获取迪斯科信息)到eureka.显然我想在Eureka中打开安全性并指定服务的用户名密码.
我有一个问题是,尝试连接到eureka的服务如何指定其凭据?是通过区域的规范和这个参考的格式是什么?
***我实际上是上面问题的答案,并在下面发布,但仍然对以下内容感到疑惑
同样,我是否可以指定更加繁重的安全机制,如果是,哪些以及如何?
我喜欢在没有领事的情况下使用测试弹簧轮廓进行单元测试.我正在尝试使用spring.cloud.config.enabled:false和禁用EnableDiscoveryClient测试配置文件的注释,但它不起作用.
我正在使用spring.cloud.consul 1.0.0.BUILD-SNAPSHOT.这是一个例外:
com.ecwid.consul.transport.TransportException:java.net.ConnectException:连接被拒绝:通过com.ecwid.consul.transport.DefaultHttpTransport连接com.ecwid.consul.transport.DefaultHttpTransport.executeRequest(DefaultHttpTransport.java:87). makeGetRequest(DefaultHttpTransport.java:46)at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:66)
我有一个简单的设置,包括Eureka服务注册服务器,公共API服务和使用RestTemplate从公共API调用的服务.Eureka告诉我服务已成功注册,但是当我打电话给服务时
@Service
public class MyServiceService {
@Autowired
private RestTemplate restTemplate;
private final String serviceUrl;
public MyServiceService() {
this.serviceUrl = "http://MY-SERVICE";
}
public Map<String, String> getTest() {
Map<String, String> vars = new HashMap<>();
vars.put("id", "1");
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
return restTemplate.postForObject(serviceUrl+"/test", "", Map.class, vars);
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下异常
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;
nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://MY-SERVICE/test": MY-SERVICE;
nested exception is java.net.UnknownHostException: MY-SERVICE] with root cause java.net.UnknownHostException: MY-SERVICE …Run Code Online (Sandbox Code Playgroud) 我有一个@FeignClient主要用于与其他微服务交谈的微服务.使用Eureka的服务发现机制,这很美妙.
现在我迫切需要使用a @FeignClient连接到外部系统,并仍使用如下所示的配置执行负载平衡.
Feign client:
@FeignClient("externalServers")
public interface ExternalServersClient {
@RequestMapping(method = RequestMethod.GET, value = "/someExternalUrl")
ResponseEntity<Object> callExternalServer();
}
Run Code Online (Sandbox Code Playgroud)
application.yml:
externalServers:
ribbon:
listOfServers: server1:18201,server2:18201
Run Code Online (Sandbox Code Playgroud)
从我经历过的许多文档中,建议禁用eureka以允许从可用的listOfServers中获取负载均衡.我确实遵循了这一点,并使用以下配置来禁用它.
application.yml:
ribbon:
eureka:
enabled: false
Run Code Online (Sandbox Code Playgroud)
这使我可以为feign客户端定位外部系统执行负载平衡,但是所有其他需要使用服务发现的假装客户端都已破坏.
有没有办法为外部系统单独禁用eureka for feign客户端设置,但允许其为其他客户端正常运行?
提前致谢!
我对Spring Cloud和Spring外部配置的概念很陌生,实际上是昨天开始的.
我创建了一个Config Server从本地Git存储库中挑选配置,一个微服务也是配置客户端和一个Eureka驱动的服务发现服务器.
以下是我主要从互联网上的各种资源中借用的代码 -
配置服务器 - application.yml:
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: file:///${user.home}/config-repo
Run Code Online (Sandbox Code Playgroud)
配置服务器 - 主类(引导程序)
@EnableConfigServer
@SpringBootApplication
public class CloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(CloudConfigServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
config-repo是我机器上的本地git repo,并且有一个.yml文件,其名称为config client application,即authmanager.yml
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
healthcheck:
enabled: true
lease:
duration: 5
spring:
application:
data:
mongodb:
host: localhost
port: 27017
database: edc_mc
logging:
level:
org.exampledriven.eureka.customer.shared.CustomerServiceFeignClient: FULL
Run Code Online (Sandbox Code Playgroud)
现在运行配置服务器后,下面是端点http:// localhost:8888/authmanager/default的输出 -
{"name":"authmanager","profiles":["default"],"label":"master","version":"0ca6ca7b4502b9bb6ce1bf8efeb25516682cf79a","propertySources":[{"name":"file:///C:\\Users\\username/config-repo/authmanager.yml","source":{"eureka.client.serviceUrl.defaultZone":"http://127.0.0.1:8761/eureka/","eureka.client.healthcheck.enabled":true,"eureka.client.lease.duration":5,"spring.application.data.mongodb.host":"localhost","spring.application.data.mongodb.port":27017,"spring.application.data.mongodb.database":"db_name","logging.level.org.exampledriven.eureka.customer.shared.CustomerServiceFeignClient":"FULL"}}]}
Run Code Online (Sandbox Code Playgroud)
微服务+配置客户端代码 -
bootstrap.yml -
server:
port: 9097
spring: …Run Code Online (Sandbox Code Playgroud) spring-boot spring-cloud spring-cloud-netflix spring-cloud-config
我正在研究春天可以.我现在拥有的是spring cloud配置服务器和eureka服务器.
配置服务器的代码
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
application.properties
spring.application.name=config-server
spring.cloud.config.server.git.uri=https://github.com/vincentwah/spring-cloud-config-repository/
server.port=7001
Run Code Online (Sandbox Code Playgroud)
Eureka服务器的代码
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
bootstrap.properties
spring.application.name=eureka-server
spring.cloud.config.uri=http://localhost:7001/
Run Code Online (Sandbox Code Playgroud)
eureka-server的配置是https://github.com/vincentwah/spring-cloud-config-repository/blob/master/eureka-server.properties
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
Run Code Online (Sandbox Code Playgroud)
当我启动eureka服务器时,我想更改端口,所以我运行下面的命令
java -jar target/eureka-server-0.0.1-SNAPSHOT.jar --server.port=1234
Run Code Online (Sandbox Code Playgroud)
但是,服务器仍然使用端口1111启动
2017-01-03 14:04:11.324 INFO 6352 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2017-01-03 14:04:11.339 INFO 6352 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server …Run Code Online (Sandbox Code Playgroud) 我尝试使用Config Server实现spring外部配置.它在应用程序启动时第一次正常工作,但没有反映对属性文件的任何更改.我尝试使用/刷新端点来动态刷新我的属性,但它似乎没有工作.任何有关这方面的帮助都会非常有帮助.
我尝试POSTing到localhost:8080/refresh但得到了404错误响应.
下面是我的应用程序类的代码
@SpringBootApplication
public class Config1Application {
public static void main(String[] args) {
SpringApplication.run(Config1Application.class, args);
}
}
@RestController
@RefreshScope
class MessageRestController {
@Value("${message:Hello default}")
private String message;
@RequestMapping("/message")
String getMessage() {
return this.message;
}
}
Run Code Online (Sandbox Code Playgroud)
和POM文件是
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.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.M8</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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> …Run Code Online (Sandbox Code Playgroud) 我正在建立基于Netflix Eureka的微服务,并在Spring-cloud之上进行实验,经过数周的研究和开发,问题就出现了!
为什么我需要Eureka和spring-cloud?
为什么不开发你的独立容器并将它们作为pods 部署在Kubernetes上并从那里维护一切?
您也可以支持Kubernetes的负载平衡,服务注册,监控,容器化等.
以下是我能想到的一些观点:
在学习微服务的编码练习中,我创建了一个Netflix Zuul项目,用于对微服务进行服务路由。
可悲的是,/ routes端点似乎没有被挂载。一切似乎都正常:定义前缀并为我的服务设置特定的路由。
zuul服务器日志文件上没有错误。当我尝试在邮递员上访问/ routes网址时,出现404错误:

我的Zuul应用程序类:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableZuulProxy
public class ZuulServerApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <!--should be set to 4.0.0 -->
<groupId>com.booking.system.hotel</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>hotel-gateway-service-server</artifactId>
<name>Hotel Gateway service - zuul</name>
<description>Hotel Gateway service - it uses Netflix Zuul Proxy Server</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties> …Run Code Online (Sandbox Code Playgroud) java microservices spring-cloud netflix-zuul spring-cloud-netflix