6

In my spring starter project, I am trying to do API calls using the JPA. My pom.xml look like this:

4.0.0

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.8.5</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
When I try to run it is getting error as

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/Module

1
  • "NoClassDefFoundError" mean that that class was present when that part of the code was compiled, but isn't present at runtime. Commented Nov 27, 2017 at 14:40

3 Answers 3

8

spring-boot-starter-web already includes Jackson. You should not override the managed version, otherwise the versions can be different between different Jackson libraries, causing ClassNotFoundException.

Remove this from the pom:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.8.5</version>
</dependency>

and let the transitive dependency with the correct version be used.

Or when you add Jackson to your pom, just don't use any version number, since parent project dependency management already includes all jackson libraries with a consistent version.

Sign up to request clarification or add additional context in comments.

Comments

2

Try 2 options :

 <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.8</version>

or

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>

5 Comments

Thank you for your response. I have added the following to pom.xml: <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.4.3</version> </dependency>
Now the error is gone. But while running getting an error as "Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat". Can you please help me to resolve this
@Programmer ,it's problem with starting server Tomcat.First attempt to try-stop & clean Tomcat,and start server....if it's not starting,then second attempt:refactor with config:@SpringBootApplication,@ComponentScan...
I have added @SpringBootApplication,@EnableAutoConfiguration,@Configuration,@ComponentScan({"controller","service"}) the above lines to my main class and tried. Still, the error is there.
@Programmer , then try removing this @ComponentScan({"‌controller","service‌​"}) and refactor server
0

If you are using SpringBoot you should know that Jackson is added by default. so remove to avoid conflicting versions and it should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.