原因:java.lang.NoSuchMethodError:org.springframework.web.bind.annotation.RequestMapping.path()[Ljava/lang/String;

nzkunb0c  于 2023-09-29  发布在  Spring
关注(0)|答案(2)|浏览(125)

org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0”的bean时出错:调用init方法失败;嵌套异常为java.lang.NoSuchMethodError:org.springframework.web.bind.annotation.RequestMapping.path()[Ljava/lang/String;
原因:java.lang.NoSuchMethodError:org.springframework.web.bind.annotation.RequestMapping.path()[Ljava/lang/String;
被这个错误卡住了几个小时。
我的pom.xml

<?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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.social</groupId>
    <artifactId>sample-social</artifactId>
    <name>ezhire</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.8</java-version>
        <org.springframework-version>4.2.1.RELEASE</org.springframework-version>
        <org.springframework.social-version>1.1.0.RELEASE</org.springframework.social-version>
        <org.springframework.social.google-version>1.0.0.RELEASE</org.springframework.social.google-version>
        <org.springframework.security-version>4.0.2.RELEASE</org.springframework.security-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <!-- Spring Social -->
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-core</artifactId>
            <version>${org.springframework.social-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-web</artifactId>
            <version>${org.springframework.social-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-google</artifactId>
            <version>${org.springframework.social.google-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-crypto</artifactId>
            <version>${org.springframework.security-version}</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>

        <!-- Logging -->

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Jade -->
        <dependency>
            <groupId>de.neuland-bfi</groupId>
            <artifactId>spring-jade4j</artifactId>
            <version>0.4.0</version>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

应用程序未启动。所有Spring框架依赖项都在同一版本上,但仍然得到相同的错误。

更新

mvn依赖项的结果:树

[INFO] com.accolite:ezhire:war:1.0.0-BUILD-SNAPSHOT
[INFO] +- org.springframework:spring-context:jar:4.2.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.2.1.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.2.1.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.2.1.RELEASE:compile
[INFO] +- org.springframework.social:spring-social-core:jar:1.1.0.RELEASE:compil
e
[INFO] +- org.springframework.social:spring-social-web:jar:1.1.0.RELEASE:compile

[INFO] +- org.springframework.social:spring-social-google:jar:1.0.0.RELEASE:comp
ile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.3:compile
[INFO] |  +- org.springframework.social:spring-social-config:jar:1.1.0.RELEASE:c
ompile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.3.3:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile
[INFO] +- org.springframework.security:spring-security-crypto:jar:4.0.2.RELEASE:
compile
[INFO] +- org.aspectj:aspectjrt:jar:1.6.10:compile
[INFO] +- javax.inject:javax.inject:jar:1:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- de.neuland-bfi:spring-jade4j:jar:0.4.0:compile
[INFO] |  +- de.neuland-bfi:jade4j:jar:0.4.0:compile
[INFO] |  |  +- org.apache.commons:commons-jexl:jar:2.1.1:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] |  |  +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-l
ru:jar:1.3.1:compile
[INFO] |  |  \- org.pegdown:pegdown:jar:1.1.0:compile
[INFO] |  |     +- org.parboiled:parboiled-core:jar:1.0.2:compile
[INFO] |  |     \- org.parboiled:parboiled-java:jar:1.0.2:compile
[INFO] |  |        +- asm:asm:jar:3.3.1:compile
[INFO] |  |        +- asm:asm-util:jar:3.3.1:compile
[INFO] |  |        +- asm:asm-tree:jar:3.3.1:compile
[INFO] |  |        \- asm:asm-analysis:jar:3.3.1:compile
[INFO] |  +- commons-io:commons-io:jar:2.1:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.6.0:compile
[INFO] +- junit:junit:jar:4.7:test
[INFO] +- org.springframework:spring-jdbc:jar:4.2.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.2.1.RELEASE:compile
[INFO] +- org.apache.commons:commons-dbcp2:jar:2.1.1:compile
[INFO] |  +- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.4:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.4:compile
[INFO] +- org.springframework:spring-core:jar:4.2.1.RELEASE:compile
[INFO] \- org.springframework:spring-web:jar:4.2.1.RELEASE:compile

看起来这里一切都很好。

isr3a4wc

isr3a4wc1#

我遇到了问题并解决了它。是因为jar版本冲突。我遇到问题的过程

  1. 1.我在pom.xml中首先使用4.2.0.release spring
    1.但我发现这似乎是错的
    1.然后我将4.2.0.release更改为4.0.2.release
    1.然后将4.0.2.release更改为4.2.0.release,并在服务器上运行
    1.我遇到了问题
    1.最后,我改变了版本,它运行了。我用的是4.0.2版本。
pengsaosao

pengsaosao2#

对我来说,这是org.springframework:spring-web版本不匹配。org.springframework. Boot :spring-boot-starter-web:3.1.0解决的版本6.0.9和我在pom - 6.0.0中提供的版本之间存在冲突。将版本更改为6.0.9后,错误消失。

<springframework.version>3.1.0</springframework.version>
<springweb.version>6.0.9</springweb.version>
...
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${springweb.version}</version>
</dependency>

相关问题