0
votes

I have created Maven project in which I had mention spring-boot-starter-web in which I already get slf4j-api-1.7.25.jar and I am using JDK9. But it could not found the org/slf4j/LoggerFactory

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) at org.springframework.boot.SpringApplication.(SpringApplication.java:179) at com.javaqubes.app.HelloWorldSpringBootApp.main(HelloWorldSpringBootApp.java:9) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 5 more

Source code :

package com.javaqubes.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloWorldSpringBootApp {
    public static void main(String[] args) {
        SpringApplication.run(HelloWorldSpringBootApp.class,args);
    }
}

Controller :

package com.javaqubes.app.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    @RequestMapping(value = "/")
    public String hello() {
        return "Hello World ...... !!!!!";
    }
}

pom.xml : 

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.javaqubes.app</groupId>
    <artifactId>01-HelloWorldSpringBoot</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>
    </dependencies>
</project>
1
You need to add SLF4J dependencyKedar Joshi
I do already have "slf4j-api-1.7.25.jar" in which I do have "LoggerFactory.class". But still showing this error. I think with JDK9, this has some issue but I don't know what's the issue, Please someone guide meEr. Sandeep Pal
@Henry that's already done by the Spring Boot starter in this case.dunni

1 Answers

0
votes

Spring Boot 1.5 does not support Java 9. You have to use Spring Boot 2 or downgrade to Java 8. See also the following article: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-Java-9