Error creating bean with name 'requestMappingHandlerAdapter'

后端 未结 4 1807
囚心锁ツ
囚心锁ツ 2021-01-11 17:19

Am creating a simple REST service using Springframework with Tomcat. The response should have to be in json like {\"id\":\"101\",\"name\":\"Ram\"} .When ever I run, am getti

相关标签:
4条回答
  • 2021-01-11 17:52
        <!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
    

    I received the same error. I removed the version.

        <!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
        </dependency>
    

    This effectively downloaded: <javax-validation.version>2.0.1.Final</javax-validation.version> which works without the error.

    0 讨论(0)
  • 2021-01-11 17:55

    Your cause is

    nested exception is java.lang.ClassCastException: org.springframework.web.accept.ContentNegotiationManagerFactoryBean$$EnhancerByCGLIB$$88a811cb cannot be cast to org.springframework.web.accept.ContentNegotiationManager

    This is probably due to both <mvc:annotation-driven /> and @EnableWebMvc are used together. As they are not complementary, either use @EnableWebMvc with Java based config or <mvc:annotation-driven /> with xml.

    0 讨论(0)
  • 2021-01-11 17:59

    In your User.java class add @javax.persistence.Id above getUserID() method

    just like this...

    @javax.persistence.Id
    public int getUserID() {
        return userID;
    }
    

    It worked for me.

    0 讨论(0)
  • 2021-01-11 18:15

    for me removing following from pom.xml fixed the issue

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>
    

    as i was also using

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
    0 讨论(0)
提交回复
热议问题