spring-cloud-gateway打包运行报错,Error creating bean with name ‘discoveryLocatorProperties’
昨天试了无数次,每次idea上可以运行,但是打包成jar包,执行就报错:
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
解决办法:在pom中还要加一个依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>