标签: spring-cloud

Spring Cloud Bus 不再支持对 /actuator/bus-refresh 的 POST 请求

我发现 Spring Cloud Bus在version上不支持对/actuator/bus-refresh 的POST 请求。当我尝试发送它时,我收到 405“方法不允许”。有没有办法在不使用/monitor和 git webhooks 或降级 Spring Cloud 版本的情况下自动刷新所有客户端服务的配置?Spring Cloud2020.0.0

我已经包含了spring-cloud-starter-bus-amqp依赖spring-boot-starter-actuator项,bus-refresh端点已公开。RabbitMQ 已启动并正在运行,在我的服务启动时创建了 springCloudBus 主题并添加了队列。当我向/actuator/bus-refresh发出 GET 请求时,它会将属性源获取到我的配置服务器,但我的客户端服务属性文件不会刷新,消息也不会添加到队列中。

spring-cloud spring-boot-actuator spring-cloud-config spring-cloud-bus

2
推荐指数
1
解决办法
2488
查看次数

Spring Cloud Gateway 和 Netflix/Eureka - 无效主机 lb://

我正在进入 Spring Cloud 2020.0.0 世界。

\n

我有一个配置服务器、网关服务器、尤里卡服务器和第一个微服务设置,并部署在开发环境中,它们都可以在其中相互通信。它们都是配置优先的,并且都成功从配置服务器拉取属性源,然后向尤里卡服务器注册。因为至少现在我没有为我的服务应用程序设置 DNS,所以我有preferIpAddress: true.

\n

Eureka实例注册

\n

将日志级别跟踪 spring-cloud-gateway,我看到发现客户端选择了这些 eureka 注册的应用程序:

\n
    2021-01-28 14:49:28.438 DEBUG 14432 --- [           main] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition ReactiveCompositeDiscoveryClient_CLOUD-SERVICES-CONFIG applying {pattern=/CLOUD-SERVICES-CONFIG/**} to Path\n    \n    2021-01-28 14:49:28.476 DEBUG 14432 --- [           main] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition ReactiveCompositeDiscoveryClient_CLOUD-SERVICES-CONFIG applying filter {regexp=/CLOUD-SERVICES-CONFIG/(?<remaining>.*), replacement=/${remaining}} to RewritePath\n    \n    2021-01-28 14:49:28.509 DEBUG 14432 --- [           main] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition matched: ReactiveCompositeDiscoveryClient_CLOUD-SERVICES-CONFIG\nand so on...\n
Run Code Online (Sandbox Code Playgroud)\n

在本地运行 API 网关(我也有一个部署的实例),Postman GET @http://localhost:8080/DATA-SERVICES-PERSON-1_0结果Route matched: ReactiveCompositeDiscoveryClient_DATA-SERVICES-PERSON-1_0以及

\n …

spring-cloud spring-cloud-netflix spring-cloud-gateway

2
推荐指数
1
解决办法
2175
查看次数

在 Spring Cloud Sleuth 中保持 CompletableFuture 的跟踪/跨度

我正在将 Sleuth 与CompletableFuture.handle. 例子:

log.info("first");
apnsClient.sendNotification(...).handle((response, cause) -> {
     log.info("second");
});
Run Code Online (Sandbox Code Playgroud)

我希望second日志具有与first日志相同的跟踪 ID。然而,事实并非如此。因此我想知道该怎么办?谢谢!

PS 我无法控制如何apnsClient.sendNotification管理线程(因为它来自Pushy),因此无法使用LazyTraceExecutor之类的东西。

java spring spring-cloud completable-future spring-cloud-sleuth

2
推荐指数
1
解决办法
2570
查看次数

如何使用 spring-cloud-aws-messaging 或 aws-java-sdk 设置 AWS SNS 消息属性值?

我有一个标准的 SNS 主题,并且我\xc2\xb4ve 设置了“订阅过滤策略”,如下所示:

\n
{\n  "event": [\n    "eventName"\n  ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n

当我使用属性消息通过 AWS 控制台发布消息时,该消息将发送至正确的 SQS 订阅者。所以订阅过滤器工作得很好。

\n

现在我正在尝试对我的 java 代码(Spring Boot)执行相同的操作。

\n

我正在使用该库spring-cloud-aws-messaging,据我所知它只是 AWS JDK 的包装器。

\n

问题是我不知道如何设置消息属性,就像我在 AWS 控制台上所做的那样。

\n

\xc2\xb4 与我发送到 SNS 的 JSON 格式无关,属性始终位于 SNS 消息的正文中。我想有一个特定的方法来设置这些属性。

\n

我发现com.amazonaws.services.sns.model.MessageAttributeValue

\n

我不确定是否是正确的类,而且我无法理解如何发布消息和属性,因为发布方法不接受它。

\n
this.amazonSNS.publish(this.snsTopicARN, message, messageAttributes ???);\n
Run Code Online (Sandbox Code Playgroud)\n

java amazon-web-services amazon-sns spring-cloud spring-cloud-aws

2
推荐指数
1
解决办法
5654
查看次数

无法调用“org.springframework.cloud.netflix.eureka.CloudEurekaClient.getApplications()”

我将 Gradle 配置更新为最新的 Spring Cloud 版本和 Spring 版本:

plugins {
    id 'org.springframework.boot' version '2.5.5'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.test'
version = '0.0.1'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "2020.0.4")
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
    implementation 'org.springframework.cloud:spring-cloud-starter-loadbalancer'
    implementation 'com.netflix.eureka:eureka-core'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'javax.validation:validation-api'
    implementation 'org.hibernate.validator:hibernate-validator'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.threeten:threetenbp:1.5.1'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    // Lombok
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
    // Mapstruct
    implementation 'org.mapstruct:mapstruct:1.4.2.Final'
    annotationProcessor …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot spring-cloud

2
推荐指数
1
解决办法
9142
查看次数

Spring Cloud openfeign 3.0.1 回退未被触发

我正在使用 spring-cloud-starter-openfeign 的 3.0.1 版本,并且在后备实现方面遇到问题。如果发生任何异常,似乎不会触发它。

我使用无效主机作为 url 配置了一个假客户端,以引发异常:

@FeignClient(name = "feignClientTest", url = "invalid.url", fallback = FeignClientTest.FallbackTest.class)
public interface FeignClientTest {

    @RequestMapping(method = RequestMethod.GET, value = "/fake/url")
    String getFromFakeUrl();

    @Component
    class FallbackTest implements FeignClientTest {

        private final Logger log = LoggerFactory.getLogger(this.getClass());

        @Override
        public String getFromFakeUrl() {
            log.debug("Fallback occurred for getFromFakeUrl");
            return "Fallback";
        }
    }
}


Run Code Online (Sandbox Code Playgroud)

调用 getFromFakeUrl() 方法后,我得到一个 java.net.UnknownHostException,而不是后备实现中使用的“Fallback”字符串。

我在应用程序配置文件中设置 feign.Circuitbreaker.enabled=true 。

我还应该配置什么吗?我错过了什么吗?

提前致谢。

spring-cloud

2
推荐指数
1
解决办法
6746
查看次数

获取 Spring Boot [2.7.0] 与此 Spring Cloud 发布列车错误不兼容

我是春天的新手。

我试图在现有的 Spring Batch 项目中将Spring Boot 版本从2.3.3.RELEASE升级到2.6.7 。

项目构建成功完成,但是当我运行批处理时出现以下错误。请帮忙。

***************************
APPLICATION FAILED TO START
***************************

Description:

Your project setup is incompatible with our requirements due to following reasons:

- Spring Boot [2.6.7] is not compatible with this Spring Cloud release train

Action:
Consider applying the following actions:
- Change Spring Boot version to one of the following versions [2.3.x, 2.4.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn]. 
If you want to learn more …
Run Code Online (Sandbox Code Playgroud)

gradle spring-boot spring-cloud spring-cloud-config spring-boot-2.6.0

2
推荐指数
1
解决办法
3万
查看次数

OpenFeign 请求抛出 AbstractMethodError

要求:

    @Headers("userId: {userId}")
    @RequestMapping(method = RequestMethod.GET, value = "/token")
    String getToken(@RequestHeader(name = "userId") Long userId);
Run Code Online (Sandbox Code Playgroud)

处理程序:

    @GetMapping("/token")
    public ResponseEntity<?> getToken(@RequestHeader String userId) throws NoSuchAlgorithmException, InvalidKeySpecException {
        String token = jwtAuth.generateToken(userId);
        return ok(token);
    }
Run Code Online (Sandbox Code Playgroud)

例外:

java.lang.AbstractMethodError:接收器类org.springframework.cloud.openfeign.support.SpringDecoder$FeignResponseAdapter没有定义或继承接口org.springframework的解析方法'abstract org.springframework.http.HttpStatusCode getStatusCode()'的实现.http.client.ClientHttpResponse。

不确定我在这里做错了什么。如果需要,我可以发布完整的堆栈跟踪

OpenFeign版本是3.1.5 Springboot 3

spring-boot spring-cloud openfeign

2
推荐指数
1
解决办法
5346
查看次数

文件上传春云假装客户端

当使用spring cloud netflix的假客户端从一个微服务发送到另一个微服务的帖子请求时,我在Postman中收到以下错误:

{
"timestamp": 1506933777413,
"status": 500,
"error": "Internal Server Error",
"exception": "feign.codec.EncodeException",
"message": "Could not write JSON: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile[\"inputStream\"]->java.io.FileInputStream[\"fd\"])",
"path": "/attachments"
}
Run Code Online (Sandbox Code Playgroud)

我的eclipse控制台显示以下异常:

com.fasterxml.jackson.databind.JsonMappingException:没有为类java.io.FileDescriptor找到序列化程序,也没有发现创建BeanSerializer的属性(为了避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链:org.springframework.web.multipart. support.StandardMultipartHttpServletRequest $ StandardMultipartFile ["inputStream"] - > java.io.FileInputStream ["fd"])at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:284)〜[jackson-databind-2.8. 9.jar:2.8.9]在com.fasterxml.jackson的com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110)〜[jackson-databind-2.8.9.jar:2.8.9]. databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135)〜[jackson-databind-2.8.9.jar:2.8.9] at …

java multipart microservices spring-cloud feign

1
推荐指数
2
解决办法
5280
查看次数

真的,不可能对Spring Data JPA @Query进行单元测试吗?

首先,目标.什么是单元测试?单元测试是测试最小功能的测试,与测试更多的集成测试相反,例如:

  • 以任何方式或任何形式生成ApplicationContext的测试不是单元测试;
  • 触摸甚至意识到应用程序(标有@SpringBootApplication)类的测试不是单元测试;
  • 加载某些东西的src/main/resources测试不是单元测试
  • 从Spring Cloud Config服务器加载外部配置的测试绝对不是单元测试;
  • 存储库的单元测试不得启动(甚至不知道)web,mvc或安全问题.

那么,如何为Spring Data JPA存储库编写单元测试?(或者那么受欢迎和喜爱的框架不支持纯单元测试这样的事情吗?)

我的项目:Spring Cloud(云计算服务,安全OAuth2服务,尤里卡,zuul,身份验证,授权等)

让我们尝试测试最简单的存储库:

public interface StudentRepository extends CrudRepository<Student, Integer> {
    Optional<Student> findByStudentCode(Integer studentCode);
    Optional<Student> findTopByOrderByStudentCodeDesc();

    @Query(value = "SELECT COUNT(*) = 0 FROM t_student WHERE regexp_replace(LOWER(student_name), '\\s', '', 'g') = regexp_replace(LOWER(:suspect), '\\s', '', 'g')", nativeQuery = true)
    boolean isStudentNameSpeciallyUnique(@Param("suspect") String studentName);
}
Run Code Online (Sandbox Code Playgroud)

学生实体将具有:id,代码(自然ID),姓名,年龄.没什么特别的.这是测试.我们需要一个SUT(我们的存储库)和实体管理器来预填充SUT.所以:

@RunWith(SpringRunner.class)
@DataJpaTest // <-- loads full-blown production app context and fails!
public class StudentRepositoryTest {

    @Autowired
    TestEntityManager manager;

    @Autowired
    StudentRepository repository;

    @Test
    public void findByStudentCode_whenNoSuch_shouldReturnEmptyOptional() …
Run Code Online (Sandbox Code Playgroud)

unit-testing spring-test spring-data-jpa spring-boot spring-cloud

1
推荐指数
1
解决办法
1260
查看次数