我发现 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
我正在进入 Spring Cloud 2020.0.0 世界。
\n我有一个配置服务器、网关服务器、尤里卡服务器和第一个微服务设置,并部署在开发环境中,它们都可以在其中相互通信。它们都是配置优先的,并且都成功从配置服务器拉取属性源,然后向尤里卡服务器注册。因为至少现在我没有为我的服务应用程序设置 DNS,所以我有preferIpAddress: true.
将日志级别跟踪 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...\nRun 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以及
我正在将 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
我有一个标准的 SNS 主题,并且我\xc2\xb4ve 设置了“订阅过滤策略”,如下所示:
\n{\n "event": [\n "eventName"\n ]\n}\nRun Code Online (Sandbox Code Playgroud)\n当我使用属性消息通过 AWS 控制台发布消息时,该消息将发送至正确的 SQS 订阅者。所以订阅过滤器工作得很好。
\n现在我正在尝试对我的 java 代码(Spring Boot)执行相同的操作。
\n我正在使用该库spring-cloud-aws-messaging,据我所知它只是 AWS JDK 的包装器。
问题是我不知道如何设置消息属性,就像我在 AWS 控制台上所做的那样。
\n\xc2\xb4 与我发送到 SNS 的 JSON 格式无关,属性始终位于 SNS 消息的正文中。我想有一个特定的方法来设置这些属性。
\n我发现com.amazonaws.services.sns.model.MessageAttributeValue
我不确定是否是正确的类,而且我无法理解如何发布消息和属性,因为发布方法不接受它。
\nthis.amazonSNS.publish(this.snsTopicARN, message, messageAttributes ???);\nRun Code Online (Sandbox Code Playgroud)\n java amazon-web-services amazon-sns spring-cloud spring-cloud-aws
我将 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-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 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
要求:
@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 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 …
首先,目标.什么是单元测试?单元测试是测试最小功能的测试,与测试更多的集成测试相反,例如:
src/main/resources测试不是单元测试那么,如何为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
spring-cloud ×10
spring-boot ×4
java ×3
spring ×2
amazon-sns ×1
feign ×1
gradle ×1
multipart ×1
openfeign ×1
spring-test ×1
unit-testing ×1