1
votes

I use Maven, Java 10, Spring boot 2 and Junit 5 for create my application with unit tests.

Main application class:

package mypackage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyApplication {

    private final static Logger LOGGER = LoggerFactory.getLogger(MyApplication.class);

    public static void main(String[] args) {
        LOGGER.info("I'am running...");
        SpringApplication.run(MyApplication.class, args);
    }
}

My JUnit test class:

package mypackage;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;


@ExtendWith(SpringExtension.class)
@SpringBootTest(classes=MyTest.class)
public class MyTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(MyTest.class);
    @Test
    public void myTest() {
        LOGGER.info("Message from test");
    }
}

When i import my maven project in Eclipse 4.10, i get error on my test class:

The package org.slf4j is accessible from more than one module: <unnamed>, slf4j.api

But mvn install work fine and maven-surefire-plugin run correct. What i'm doing wrong? Or it's eclipse bug? Maybe Java 10, Junit and SLF4J not working together? in my module-info.java: requires slf4j.api;

Please help me.

3

3 Answers

1
votes

I believe you've added the jar for slf4j to the ModulePath:

Go to Project -> BuildPath -> Config BuildPath -> Remove Jars from Modulepath

0
votes

This happens when you have added the external jars in the ModulePath. Remove those added external jars and add dependency using pom.xml

Check under Dependency Hierarchy, slf4j library should be under one dependency

0
votes

Need remove module-info.class from your spring-boot project. spring-boot/#16031