一. 项目启动不起来


很奇怪在另一台电脑可以,但是换了一台电脑就不行了,两台电脑的区别仅仅是idea编辑器不一样,一个是社区版,一个是专业版。

  1. 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
  2. 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
  3. Caused by: java.lang.NoClassDefFoundError: javax/validation/ValidationException

解决方案:根据 Spring Boot 2.3 Release Notes ,Validation Starter不再包含在Web Start中,所以需要我们额外的引入Validation的依赖包。2.3版本以后Validation Starter不再包含在Web Start中,得额外引入:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-validation</artifactId>
  4. </dependency>