gpt4 book ai didi

spring-cloud-gateway - 无法使用 Spring Cloud Hoxton SR4 在 Spring-Cloud-Gateway 中实例化 DiscoveryLocatorProperties

转载 作者:行者123 更新时间:2023-12-01 21:35:19 34 4
gpt4 key购买 nike

感谢任何有助于解决以下问题的帮助。我正在使用 Spring Cloud Hoxton.SR4 并使用 spring-cloud-starter-gateway 创建了一个网关服务。应用程序在启动时抛出以下异常。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'discoveryClientRouteDefinitionLocator' defined in class path resource [org/springframework/cloud/gateway/discovery/GatewayDiscoveryClientAutoConfiguration$ReactiveDiscoveryClientRouteDefinitionLocatorConfiguration.class]: Unsatisfied dependency expressed through method 'discoveryClientRouteDefinitionLocator' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'discoveryLocatorProperties' defined in class path resource [org/springframework/cloud/gateway/discovery/GatewayDiscoveryClientAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties]: Factory method 'discoveryLocatorProperties' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/validation/ValidationException
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties]: Factory method 'discoveryLocatorProperties' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/validation/ValidationException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
... 39 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/validation/ValidationException
at org.springframework.cloud.gateway.discovery.GatewayDiscoveryClientAutoConfiguration.initPredicates(GatewayDiscoveryClientAutoConfiguration.java:61) ~[spring-cloud-gateway-core-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.gateway.discovery.GatewayDiscoveryClientAutoConfiguration.discoveryLocatorProperties(GatewayDiscoveryClientAutoConfiguration.java:86) ~[spring-cloud-gateway-core-2.2.2.RELEASE.jar:2.2.2.RELEASE]enter code here
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_212]
at sun.reflect.DelegatingMethodAccessorImpl.invoenter code hereke(Unknown Source) ~[na:1.8.0_212]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_212]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
... 40 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.validation.ValidationException


at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_212]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_212]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_212]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_212]
... 47 common frames omitted>

我也在 application.properties 中添加了以下条目;但这并没有解决问题

spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lower-case-service-id=true

最佳答案

看这个:Spring Boot 2.3 Release Notes

它说:

As of #19550, Web and WebFlux starters do not depend on the validation starter by default anymore. If your application is using validation features, you’ll need to manually add back a dependency on spring-boot-starter-validation in your build file.

Spring Initializr 似乎没有接受这个,所以现在每个人都缺少验证启动程序。

将以下内容添加到您的 <dependencies> 中的 POM block :

    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

关于spring-cloud-gateway - 无法使用 Spring Cloud Hoxton SR4 在 Spring-Cloud-Gateway 中实例化 DiscoveryLocatorProperties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62042547/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com