从spring doc,我看到我们可以将peer eureka服务器放在一起,所以对于Eureka1,在application.yml中,我可以:
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2/eureka/
Run Code Online (Sandbox Code Playgroud)
在Eureka Server 2中,我可以:
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1/eureka/
Run Code Online (Sandbox Code Playgroud)
现在这两个eureka服务器互相认识,这很好.但是,现在在配置客户端时,当他们再次注册Eureka时,该怎么做?
在我的客户端应用程序中,我有:
eureka:
instance:
hostname: ${host.instance.name:localhost}
nonSecurePort: ${host.instance.port:8080}
leaseRenewalIntervalInSeconds: 5 #default is 30, recommended to keep default
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
serviceUrl:
defaultZone: http://(eurekaServerHost):8761/eureka/
server:
port: ${host.instance.port:8080}
Run Code Online (Sandbox Code Playgroud)
所以现在我的问题是我应该在客户端application.yml中使用peer1或peer2作为EurekaServerHost吗?
谢谢
我们将现有的Spring Web应用程序部署为Amazon Elastic Beanstalk中的WAR文件.目前,我们将属性文件作为http资源加载,以便为我们提供单一的属性占位符配置解析源.我正在调查用新的Spring云配置服务器替换它,以便为我们提供git版本控制等的好处.
但是文档(http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html)似乎只描述了一个Spring Boot客户端应用程序.是否可以在现有的Web应用程序中设置Spring Cloud Config Client?我是否需要手动设置Bootstrap父应用程序上下文等 - 这是否有任何示例?我们当前的spring配置是基于XML的.
我们正在尝试在UI和应用程序/服务之间构建新的Business API层.
春季哪个项目最好,将满足开发Biz Api和宁静服务的需求?
难道Spring Cloud还是Spring Boot?
我正在尝试将我的 kotlin - gradle 项目从 springboot 版本 2.3.5.RELEASE 升级到 2.4.1。看起来 springboot-2.4.1 和 sping-cloud-Hoxton.SR9 之间存在版本不匹配。
build.gradle.kts 片段
plugins {
id("org.springframework.boot") version "2.4.1"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
kotlin("jvm") version "1.4.10"
kotlin("plugin.spring") version "1.4.10"
kotlin("plugin.jpa") version "1.4.10"
kotlin("plugin.serialization") version "1.4.10"
idea
}
group = "com.xxx"
version = ""
java.sourceCompatibility = JavaVersion.VERSION_11
extra["springCloudVersion"] = "Hoxton.SR9"
val resilience4jVersion = "1.3.1"
val queryDslVersion = "4.4.0"
val springCloudVersion = "Hoxton.SR9"
val cucumberVersion = "6.7.0"
val camundaVersion = "7.14.0"
var jacocoVersion = "0.8.5"
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion")
} …Run Code Online (Sandbox Code Playgroud) 我目前正在开发基于微服务架构的应用程序.我们使用使用Spring Cloud Netfix的Zuul Server实现的API网关将请求路由到我们的微服务.
要实现我们所有服务的单点登录,我目前正在使用Spring Cloud Security设置OAuth2服务器.服务器基本上只是在Dave Syer的Repo中实现的复制和过去:https://github.com/dsyer/spring-security-angular/tree/master/oauth2/authserver
主要区别在于我想通过Zuul代理将请求路由到我的OAuth服务器.这样我就不必直接暴露我的OAuth服务器,并可以动态添加和删除Login Server.
问题是我不了解如何正确配置此设置.当我尝试访问OAuth服务器上的受保护资源时,我将转发到登录页面.这当然是预期的.但我无法弄清楚如何设置转发时使用的主机名和端口.我想要发生的是服务器转发到Zuul服务器上的端点,该端点将被代理回到OAuth服务器.(Zuul API-Gateway应该是客户端与之交谈的唯一服务器.其他所有内容都将被隐藏.)
因为它是主机和端口从读HttpServletRequest在LoginUrlAuthenticationEntryPoint.但是服务器看到的请求是Zuul代理发送的请求.所以我被转发到内部IP而不是代理端点.
我尝试将登录页面WebSecurityConfigurerAdapter.configure(HttpSecurity)的URL设置为我的Zuul代理的绝对URL.但这只是导致我的应用程序抱怨太多的重定向.(可能会在那里引起循环.)
设置它的最佳方法是什么?
是否可以将动态值设置为标题?
@FeignClient(name="Simple-Gateway")
interface GatewayClient {
@Headers("X-Auth-Token: {token}")
@RequestMapping(method = RequestMethod.GET, value = "/gateway/test")
String getSessionId(@Param("token") String token);
}
Run Code Online (Sandbox Code Playgroud)
注册RequestInterceptor的实现会添加标头,但无法动态设置标头值
@Bean
public RequestInterceptor requestInterceptor() {
return new RequestInterceptor() {
@Override
public void apply(RequestTemplate template) {
template.header("X-Auth-Token", "some_token");
}
};
}
Run Code Online (Sandbox Code Playgroud)
我在github上发现了以下问题,其中一个评论者(lpborges)试图在@RequestMapping注释中使用标题做类似的事情.
https://github.com/spring-cloud/spring-cloud-netflix/issues/288
亲切的问候
在我的Spring Boot 项目中,我定义了 4 个配置文件
YAML 文件中的属性将在启动期间被 HashiCorp Vault 属性替换。为此,我使用 Spring Cloud Vault 库。在 Spring Boot 2.3.x 中一切正常
当我尝试使用 Spring Cloud Vault 3.0.0-SNAPSHOT 版本将项目升级到 Spring Boot 2.4.0 时,属性没有被替换
引导程序.yml
spring:
cloud:
vault:
authentication: APPROLE
app-role:
role-id: ${role-id}
secret-id: ${secret-id}
role: pres-read
app-role-path: approle
uri: ${vault-server}
connection-timeout: 5000
read-timeout: 15000
kv:
enabled: true
backend: secret
application-name: app/pres
Run Code Online (Sandbox Code Playgroud)
应用程序.yml
spring:
config:
activate:
on-profile: 'demo'
Run Code Online (Sandbox Code Playgroud)
应用程序演示.yml
## Server Properties
server:
port: 8081
spring:
datasource:
username: ${pres.db.username}
password: …Run Code Online (Sandbox Code Playgroud) 是否可以在不使用任何Git仓库的情况下使用Spring Cloud Config?我正在尝试使用application.properties中的本地目录来测试它:
spring.cloud.config.server.git.uri=file://${user.dir}/src/main/resources/config-repo
但是我收到以下错误:
java.lang.IllegalStateException:文件中没有.git:// path/to/src/main/resources/config-repo
如果一个人根本不使用Git,那么就不可能使用Spring Cloud吗?
更新:
感谢Spencer的建议,我补充了以下内容:
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=${user.dir}/src/main/resources/configs
我在"configs"中有一个文件"bar.properties",其中包含以下内容:
foo: bar
Run Code Online (Sandbox Code Playgroud)
但我得到的反应不是读取文件:
{
"name": "bar",
"profiles": [
"default"
],
"label": "master",
"propertySources": []
}
Run Code Online (Sandbox Code Playgroud)
我正在使用的URL是http:// localhost:8888/bar/default
我错过了别的什么吗?再次感谢您!
我正在尝试使用简单的Spring OAuth2 SSO应用程序,但我无法这样做.以下是发生的事情的步骤和结果:
/user,由OAuth2保护然后,我在OAuth2 SSO应用程序上获得了一个白标错误页面,其中包含以下内容:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jul 13 08:19:18 EDT 2015
There was an unexpected error (type=Unauthorized, status=401).
Authentication Failed: Could not obtain access token
Run Code Online (Sandbox Code Playgroud)授权码位于URL中.以下是示例网址:
http://localhost:8083/login?code=9s63rU&state=Fo9S2M
Run Code Online (Sandbox Code Playgroud)
我没有看到HTTP POST授权服务器/oauth/token端点获取JWT.我通过/trace授权服务器上的端点验证了这一点.
异常堆栈是:
2015-07-13 08:23:32.695 DEBUG 3516 --- [nio-8083-exec-7] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/login'; against '/css/**'
2015-07-13 08:23:32.695 …Run Code Online (Sandbox Code Playgroud) spring spring-security spring-boot spring-security-oauth2 spring-cloud
我是春天的新手.我已阅读此文档,它说客户端应用程序必须指定服务URL:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)
但是如果localhost:8761下降怎么办?