我正在尝试创建一个Spring Cloud配置服务器,它从属性文件而不是github读取配置数据.服务器启动,但不提供文件中的属性.我在classpapath上有两个配置文件:
bootstrap.yml
spring:
application:
name: config-server
Run Code Online (Sandbox Code Playgroud)
config-server.properties
foo=bar
Run Code Online (Sandbox Code Playgroud)
当我去url,据说应该给我foo属性的值:
curl http://localhost:8888/admin/env/foo
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:"timestamp":1415298615005,"status":404,"error":"Not Found","exception":"org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint $ NoSuchPropertyException","message ":"没有这样的属性:foo","path":"/ admin/env/foo"}
我想知道我做错了什么?据我所知,属性文件名应与服务器名称匹配,以便服务器识别.
添加原生配置文件作为spencergibb建议没有帮助.我的application.properties看起来像:
server.port=8888
spring.profiles.active=native
spring.config.name=configserver
spring.application.name=configserver
Run Code Online (Sandbox Code Playgroud)
注意,我必须指定服务器端口.根据Spring Cloud Config Server文档,配置服务器默认在端口8888上启动.在我的情况下,除非我在配置中指定端口,否则服务器从8080开始.
POM文件没有父级和单个依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>1.0.0.M2</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
该应用程序没有什么特别之处:
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableConfigServer
public class ConfigurationApp {
public static void main(String[] args) {
SpringApplication.run(ConfigurationApp.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
configserver.properties文件包含一个条目:foo = bar
首先,我总是遇到启动错误
2014-11-07 09:35:42.852 ERROR 6972 --- [ main] b.c.PropertySourceBootstrapConfiguration : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/configserver/default/master":Connection refused: …Run Code Online (Sandbox Code Playgroud) 我知道我可以使用多个存储库来跨多个存储库(可能是每个应用程序)分配我的配置,但是,我可以为这些存储库运行多个配置服务器,这样我们就可以避免单点故障了配置服务器'.
如果我们可以运行多个配置服务器,我如何抽象我的客户端访问任何一个特定的配置服务器?
更新(进一步阅读后):如果我使用负载均衡多个IP的URL,而不是在URI中使用IP,它是否会解决我在Config Server上单点故障的问题?
spring.cloud.config.uri: http ://myconfigserver.com
美好的一天,
我已经设置了一个实现SSO和API网关模式的工作示例(类似于此处描述的https://spring.io/guides/tutorials/spring-security-and-angular-js/#_the_api_gateway_pattern_angular_js_and_spring_security_part_iv).
该系统由单独的服务器组件组成:AUTH-SERVER,API-GATEWAY,SERVICE-DISCOVERY,RESOURCE/UI SERVER.
在API-GATEWAY(使用Spring Boot @EnableZuulProxy @ EnableOAuth2Sso实现)我已经配置了多个OAuth提供程序,包括使用JWT的我自己的OAuth服务器:
security:
oauth2:
client:
accessTokenUri: http://localhost:9999/uaa/oauth/token
userAuthorizationUri: http://localhost:9999/uaa/oauth/authorize
clientId: acme
clientSecret: acmesecret
redirectUri: http://localhost:9000/login
resource:
jwt:
key-value: |
-----BEGIN PUBLIC KEY-----
...public-key...
-----END PUBLIC KEY-----
facebook:
client:
clientId: 233668646673605
clientSecret: 33b17e044ee6a4fa383f46ec6e28ea1d
accessTokenUri: https://graph.facebook.com/oauth/access_token
userAuthorizationUri: https://www.facebook.com/dialog/oauth
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
redirectUri: http://localhost:8080
resource:
userInfoUri: https://graph.facebook.com/me
github:
client:
clientId: bd1c0a783ccdd1c9b9e4
clientSecret: 1a9030fbca47a5b2c28e92f19050bb77824b5ad1
accessTokenUri: https://github.com/login/oauth/access_token
userAuthorizationUri: https://github.com/login/oauth/authorize
clientAuthenticationScheme: form
resource:
userInfoUri: https://api.github.com/user
google:
client:
clientId: 1091750269931-152sv64o8a0vd5hg8v2lp92qd2d4i00r.apps.googleusercontent.com
clientSecret: n4I4MRNLKMdv603SU95Ic9lJ
accessTokenUri: https://www.googleapis.com/oauth2/v3/token
userAuthorizationUri: …Run Code Online (Sandbox Code Playgroud) oauth spring-boot spring-security-oauth2 spring-cloud spring-oauth2
TLDR:我在RxJava Observables中进行后台处理,我正在进行集成测试,我希望能够独立等待该处理完成,以确保从一次测试开始的后台处理不会干扰另一个测试.
简化,我有一个@RequestMapping方法,可以执行以下操作:
HttpStatus.NO_CONTENT)这种异步处理以前是用a完成的ThreadPoolTaskExecutor.我们将转换到RxJava并希望删除此ThreadPoolTaskExecutor并使用RxJava进行后台处理.
所以我试图这样做的时候非常天真:
Observable
.defer(() -> Observable.just(call to long blocking method)
.subscribeOn(Schedulers.io())
.subscribe();
Run Code Online (Sandbox Code Playgroud)
最终目标当然是,一步一步,进入"调用长阻塞方法"并一直使用Observable.
在此之前,我想首先使我的集成测试工作.我通过对映射执行RestTemplate调试来测试它.由于大多数工作是异步的,我的调用返回非常快.现在我想找到一种方法来等待异步处理完成(以确保它不与另一个测试冲突).
在RxJava之前,我只计算ThreadPoolTaskExecutor中的任务并等到它达到0.
我怎么能用RxJava做到这一点?
我尝试了什么:
我可能非常错误,或者过于复杂的事情,所以不要犹豫,纠正我的理由!
我想用Spring Cloud定制Eureka端口.使用下面的默认端口,服务注册表看起来正确(在提供的GUI中)
spring:
application:
name: services-registry
server:
port: 8761
eureka:
instance:
hostname: localhost
nonSecurePort: ${server.port}
client:
register-with-eureka: true
fetch-registry: false
service-url:
default-zone: http://${eureka.instance.hostname}:${server.port}/eureka/
Run Code Online (Sandbox Code Playgroud)
但是,如果我只是将server.port更改为8787,那么任何服务都无法注册,甚至服务注册表本身也无法注册.
2017-01-09 16:18:21.584 WARN 17496 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure
2017-01-09 16:18:21.584 WARN 17496 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SERVICES-REGISTRY/xxx.org:services-registry:8787 - registration failed Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
...
2017-01-09 16:13:33.299 WARN 17496 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator …Run Code Online (Sandbox Code Playgroud) Spring Cloud使用以下docker代码部署项目pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.3</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${project.basedir}</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<!-- end::plugin[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
当我运行命令:时mvn package docker:build,它会抛出错误:
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.3:build (default) on project users-microservice: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused -> [Help 1]
[ERROR]
[ERROR] To …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Cloud Stream Kafka 绑定器来消费来自 Kafka 的消息。我能够使我的示例与单个 Kafka Binder 一起工作,如下所示
spring:
cloud:
stream:
kafka:
binder:
consumer-properties: {enable.auto.commit: true}
auto-create-topics: false
brokers: <broker url>
bindings:
consumer:
destination: some-topic
group: testconsumergroup
consumer:
concurrency: 1
valueSerde: JsonSerde
producer:
destination: some-other-topic
producer:
valueSerde: JsonSerde
Run Code Online (Sandbox Code Playgroud)
请注意,此处两个绑定都指向同一个 Kafka Broker。但是,我遇到了一种情况,我需要发布到某个 Kafka 集群中的一个主题,并且还需要从不同 Kafka 集群中的另一个主题进行消费。我应该如何更改配置才能绑定到不同的 Kafka 集群?
我尝试过这样的事情
spring:
cloud:
stream:
binders:
defaultbinder:
type: kafka
environment:
spring.cloud.stream.kafka.streams.binder.brokers: <cluster1-brokers>
kafka1:
type: kafka
environment:
spring.cloud.stream.kafka.streams.binder.brokers: <cluster2-brokers>
bindings:
consumer:
binder: kafka1
destination: some-topic
group: testconsumergroup
consumer:
concurrency: 1
valueSerde: JsonSerde …Run Code Online (Sandbox Code Playgroud) spring-boot spring-cloud spring-cloud-stream spring-kafka spring-cloud-stream-binder-kafka
我有一大堆使用共享配置的 Feign 客户端(MyFeignConfiguration.class):
@FeignClient(name = "clientA", url = "http://serviceA.com", fallbackFactory = ServiceAFallbackFactory.class, configuration = MyFeignConfiguration.class)
@FeignClient(name = "clientB", url = "http://serviceB.com", fallbackFactory = ServiceBFallbackFactory.class, configuration = MyFeignConfiguration.class)
@FeignClient(name = "clientC", url = "http://serviceC.com", fallbackFactory = ServiceCFallbackFactory.class, configuration = MyFeignConfiguration.class)
Run Code Online (Sandbox Code Playgroud)
但是,对于新客户端,我想将用于 OkHttp 的底层 Http 客户端更改为 OkHttp。在MyFeignConfiguration课堂上,我可以添加以下内容:
@Configuration
class MyFeignConfiguration {
@Bean
public Client getClient() {
return OkHttpClient() // use the OkHttp client
}
@Bean
public ErrorDecoder getErrorDecoder() {
//... existing configs
}
Run Code Online (Sandbox Code Playgroud)
然而,现在所有的客户端都在使用这个OkHttp客户端。如何配置新的 feign 客户端以便只有它使用 OkHttp 客户端?另外,我仍然需要使用 …
这是关于 Spring Cloud Config Server业余爱好项目(带有@EnableConfigServer)。
昨天,可以开始申请了。
\n今天,由于 Git 通信错误,应用程序无法启动。
\n从GitHub 的官方博客文章中提到,从 2022 年 3 月 15 日开始,不再支持 SHA-1。这解释了我这两天得到的结果。
\n\n\n2022 年 3 月 15 日
\n改变成为永久性的。
\n我们\xe2\x80\x99将永久停止接受 DSA 密钥。在上述截止点之后上传的 RSA 密钥仅适用于 SHA-2 签名(但同样,在此日期之前上传的 RSA 密钥将继续适用于 SHA-1)。已弃用的 MAC、密码和未加密的 Git 协议将被永久禁用。
\n
即使我没有删除现有的 SSH 密钥,今天仍然无法启动。但无论如何,现在存储库设置的“部署密钥”部分下的唯一密钥是 2022 年 3 月 15 日截止日期之后添加的 SSH 密钥。
\n依赖管理:
\n| 依赖性 | 版本 |
|---|---|
| spring-cloud-依赖项 | 霍克斯顿.SR12 |
依赖关系: …
升级到 Spring Boot 3 后,我必须更新跟踪/关联配置,以从 Spring Cloud Sleuth 切换到新的 Micrometer 跟踪库。
此时,我可以在日志中看到 traceId/spanId 信息,这些信息已使用带有自动检测的 .txt 文件的 HTTP 调用正确传输到其他服务WebClient。
然而,Spring Cloud Streams Kafka 生产者和消费者似乎没有被检测到。
这是生产者的示例:
logger.debug("Sending message to kafka queue {}", message)
streamBridge.send(bindingName, message)
Run Code Online (Sandbox Code Playgroud)
带有traceId、spanId的日志:
[producer,638b36642e4fe0b203b7f32b746b22de,03b7f32b746b22de] 52233 --- [ctor-http-nio-3] i.s.m.p.p.ProjectTaskEventProducer : Sending message to kafka queue GenericMessage [xxx]
[producer,638b36642e4fe0b203b7f32b746b22de,03b7f32b746b22de] 52233 --- [ctor-http-nio-3] o.s.c.s.binder.DefaultBinderFactory : Creating binder: kafka
Run Code Online (Sandbox Code Playgroud)
在消费者方面,我有这个简单的 KStream:
@Bean
fun processEvent() =
Function<KStream<EventKey, EventValue>, KStream<EventKey, EventValue?>> { events ->
events.process(
ProcessorSupplier {
Processor<EventKey, EventValue, EventKey, EventValue> {
logger.info("{}", …Run Code Online (Sandbox Code Playgroud) spring-boot spring-cloud spring-cloud-stream spring-kafka micrometer
spring-cloud ×10
spring-boot ×6
java ×3
spring ×3
spring-kafka ×2
config ×1
docker ×1
feign ×1
github ×1
maven-3 ×1
micrometer ×1
oauth ×1
rest ×1
rx-java ×1