首先我对这门课有一个小问题 brave.sampler.Sampler
无法导入此类,仅在添加此依赖项时导入
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave</artifactId>
<version>4.0.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的大问题是,当我尝试使用 zipkin 进行干扰跟踪时,我添加了所需的依赖项,但每当我启动应用程序时,它都会在启动时出现异常。
这是堆栈跟踪。
java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.sleuth.zipkin2.sender.ZipkinRabbitSenderConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@764c12b6]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:599) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:718) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:659) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:627) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:419) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:389) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:510) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:502) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1198) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:892) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:878) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:864) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:813) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:341) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) …Run Code Online (Sandbox Code Playgroud) 我创建了一个 github 存储库https://github.com/Nisarg04/microservices-config-repo.git,我希望将其视为配置存储库。另外,我有一个 Spring Cloud 服务器,它从本地存储库中选择属性(根据当前配置)。我希望从 github 存储库中选取它。
application.properties看起来像这样:
spring.application.name=spring-cloud-config-server
server.port=8888
#spring.cloud.config.server.git.uri=file:///C:/Users/admin/git/git-localconfig-repo
spring.cloud.config.server.git.uri=https://github.com/Nisarg04/microservices-config-repo.git
management.security.enabled=false
Run Code Online (Sandbox Code Playgroud)
当我指向 时git-localconfig-repo,它工作完美。但是,当我指向我的存储库时,它给出了错误:Cannot clone or checkout repository: https://github.com/Nisarg04/microservices-config-repo.git
我该如何解决这个问题?
编辑:也尝试过
spring.cloud.config.server.git.username=nisarg04
spring.cloud.config.server.git.password=mypassword
,但即使这样也有帮助
根据要求,我添加了以下服务器类:
@SpringBootApplication
@EnableConfigServer
public class SpringCloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud) 我们在后端服务前面使用 Spring Cloud Gateway。我们有一条类似于以下的路线:
routes:
- id: foobar-service
uri: lb://foobar-service
predicates:
- Path=/foobar/**
filters:
- StripPrefix=1
Run Code Online (Sandbox Code Playgroud)
我们想要拒绝访问一个特定的子路径(例如/foobar/baz/**),但将其余子路径保持打开状态。是否可以使用 YAML 语法来执行此操作?也许我们需要使用 Fluent API 来实现路由?
当我在没有 Spring Security 的情况下运行 Spring Cloud 配置服务器时,该服务可以毫无问题地获取配置,但是当我激活 Spring Security 时,它不会获取配置文件。似乎抛出了 401 http 错误。我已检查用户名和密码是否正确,我还尝试了 user:password@url 的身份验证方式,但存在同样的问题。
如果我直接在浏览器中访问网址http://localhost:8888/service/default并输入用户名和密码,则会显示配置。
任何帮助将不胜感激,我不确定我的云配置或安全配置是否有问题。
Spring Boot 版本:'2.2.4.RELEASE'
spring-cloud-config-server 版本:'2.2.1.RELEASE'
构建系统:Gradle
Java 8
此配置总是失败,我尝试将其添加到我拥有的现有服务中,但它不起作用,因此我通过https://start.spring.io/上的 spring 初始化程序使用以下配置创建了一个新的配置服务器和一个新客户端仍然不起作用。
当安全性处于活动状态时记录:
2020-02-19 14:29:16.553 INFO 14996 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-02-19 14:29:16.577 DEBUG 14996 --- [ main] o.s.web.client.RestTemplate : HTTP GET http://localhost:8888/service/default
2020-02-19 14:29:16.634 DEBUG 14996 --- [ main] o.s.web.client.RestTemplate : Accept=[application/json, application/*+json]
2020-02-19 14:29:16.647 DEBUG 14996 --- [ main] o.s.web.client.RestTemplate …Run Code Online (Sandbox Code Playgroud) java spring spring-security spring-cloud spring-cloud-config
请帮我解决以下问题。我想在 git repo 中为每个微服务都有一个文件夹。请参考我在 git repo 中的示例结构。https://github.com/tech-vishesh/config-server_properties
If we have same properties under different folder
like
ms-one
|--- application.properties
|--- application-prod.properties
|--- application-dev.properties
ms-two
|--- application.properties
|--- application-prod.properties
|--- application-dev.properties
we have define search path in spring cloud config bootstrap file
spring.cloud.config.server.git.search-paths=ms-one,ms-two
Now we have to load profile in client application then how we can load the profile?
I have define
spring.application.name=application
spring.profiles.active=dev
but how to define which folder.
Current spring boot version 2.2.5
Run Code Online (Sandbox Code Playgroud) 关于用于背靠背通信的最佳方式有什么想法吗?
Spring Cloud OpenFeign还是WebClient/RestTemplate?
我认为Spring Cloud Gateway需要时应该使用Feign客户端
与其他微服务通信,而WebClient/RestTemplate应该用于背对背通信。
我错了吗 ?
我正在使用 Spring Boot 2.4.1 和 Eureka 开发一个应用程序。我成功启动了 Eureka 服务器,但使用 Eureka 客户端时出现以下错误:
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.client.apache4.ApacheHttpClient4
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 55 common frames omitted
...
Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.cloud.netflix.eureka.CloudEurekaClient.getApplications()" because the return value of "org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient()" is null
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:54) ~[spring-cloud-netflix-eureka-client-3.0.0.jar:3.0.0]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:38) ~[spring-cloud-netflix-eureka-client-3.0.0.jar:3.0.0]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:83) ~[spring-cloud-netflix-eureka-client-3.0.0.jar:3.0.0]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.2.jar:5.3.2]
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties> …Run Code Online (Sandbox Code Playgroud) 我正在配置新的spring config server并收到以下错误。
***************************
APPLICATION FAILED TO START
***************************
Description:
Invalid config server configuration.
Action:
If you are using the git profile, you need to set a Git URI in your configuration. If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.
Run Code Online (Sandbox Code Playgroud)
我已尝试以下链接,但没有运气
Spring Cloud Config Server 配置与本地存储库
spring config server- 用于本地 git 存储库
https://medium.com/@danismaz.furkan/spring-cloud-config-with-file-system-后端-c18ae16b7ad5
bootstrap.properties
server.port = 8888
spring.cloud.config.server.native.search-locations=file:///C:/configprop/
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> …Run Code Online (Sandbox Code Playgroud) java spring-boot spring-cloud spring-cloud-config spring-cloud-config-server
我已将 Spring boot 依赖项从2.1to2.4.5和 spring cloud升级到2020.0.2. 升级后,我的 MDC 上下文未填充。
关于这里应该做什么有什么想法吗?
我有一个 Spring Boot 应用程序,它通过 Spring Cloud 从远程配置服务器读取属性,并且它可以与远程存储库中定义的不同配置文件配合使用,我使用以下命令运行它:
java -jar my-app.jar --spring.profiles.active=my-custom-profile
Run Code Online (Sandbox Code Playgroud)
但是,在某些特殊情况下,我希望能够在更改某些远程属性的同时运行应用程序(这些更改不是固定的,因此我无法为它们创建一些自定义配置文件),因此我尝试覆盖直接通过命令行进行操作:
java -jar my-app.jar --spring.profiles.active=my-custom-profile --my.first.property=value1 --my.second.property=value2
Run Code Online (Sandbox Code Playgroud)
但似乎没有考虑到这一点,因为应用程序在启动时仍然采用远程属性。
有没有适当的方法来实现这一目标?
spring-cloud ×10
java ×6
spring-boot ×6
spring ×2
git ×1
github ×1
maven ×1
openfeign ×1
resttemplate ×1
zipkin ×1