java.lang.NoClassDefFoundError:org/springframework/web/util/UriTemplateHandler
我有一个使用Spring初始值设定项创建的基本SpringBoot应用程序。当我尝试启动SpringBoot服务器(使用maven插件(SpringBoot:start))时,会出现以下错误 java.lang.NoClassDefFoundError: org/springframework/web/util/UriTemplateHandler位于 java.lang.Class.getDeclaredConstructors0(本机方法)~[na:1.8.0_60] 位于java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~(na:1.8.060)at getDeclaredConstructors(Class.java:2020) ~(na:1.8.060)at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.findConstructorBindingAnnotatedConstructor(ConfigurationPropertiesBindConstructorProvider.java:62) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]位于 org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.getBindConstructor(ConfigurationPropertiesBindConstructorProvider.java:48) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]位于 org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.forType(ConfigurationPropertiesBean.java:311) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]位于 org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:63) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]位于 org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]位于 org.springframework.context.support.postprocessorregistrationlegate.invokeBeanFactoryPostProcessors(postprocessorregistrationlegate.java:286) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]at org.springframework.context.support.postprocessorregistrationlegate.invokeBeanFactoryPostProcessors(postprocessorregistrationlegate.java:174) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE] 这是我的pom文件java.lang.NoClassDefFoundError:org/springframework/web/util/UriTemplateHandler,java,spring-boot,Java,Spring Boot,我有一个使用Spring初始值设定项创建的基本SpringBoot应用程序。当我尝试启动SpringBoot服务器(使用maven插件(SpringBoot:start))时,会出现以下错误 java.lang.NoClassDefFoundError: org/springframework/web/util/UriTemplateHandler位于 java.lang.Class.getDeclaredConstructors0(本机方法)~[na:1.8.0_60] 位于java.lang
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.cgtm</groupId>
<artifactId>validator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>validator</name>
<description>Validator</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Spring boot的版本是2.2.4,它需要Spring 5(基本上它附带了一个预定义的Spring版本) 另一方面,您使用的是“硬编码”SpringWeb4.1.4,这是错误的:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
最后一件事,您使用的是lombok,这当然很好(我的意思是spring可以很好地使用lombok),但是spring boot maven插件仍然会将其打包到工件中,尽管提供了
范围。如果您希望将其从最终工件中排除,您必须配置spring boot maven插件本身来实现这一点
阅读了解更多信息您是否在
eclipse上运行
?如果您在eclipse上运行,请打开项目的属性(例如,在项目浏览器中右键单击项目名称并选择“属性”)。选择“部署程序集”。单击右边空白处的“添加…”按钮。选择“Java构建路径条目”从指令类型菜单中,单击“下一步”。从Java构建路径条目菜单中选择“Maven依赖项”,然后单击“完成”。您应该看到添加到Web部署程序集定义中的“Maven依赖项”。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>