Java 弹簧靴2。爪哇10。朱尼特。可以从多个模块访问包org.slf4j:<;未命名>;,slf4j.api

Java 弹簧靴2。爪哇10。朱尼特。可以从多个模块访问包org.slf4j:<;未命名>;,slf4j.api,java,maven,spring-boot,junit,slf4j,Java,Maven,Spring Boot,Junit,Slf4j,我使用Maven、Java10、SpringBoot2和JUnit5来创建带有单元测试的应用程序 主要应用类别: package mypackage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplicati

我使用Maven、Java10、SpringBoot2和JUnit5来创建带有单元测试的应用程序

主要应用类别:

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);
    }
}
我的JUnit测试类:

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");
    }
}
The package org.slf4j is accessible from more than one module: <unnamed>, slf4j.api
在Eclipse 4.10中导入maven项目时,我的测试类出现错误:

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");
    }
}
The package org.slf4j is accessible from more than one module: <unnamed>, slf4j.api
可以从多个模块访问org.slf4j包:,slf4j.api
但是mvn安装工作正常,maven surefire插件运行正常。我做错了什么?或者是eclipse bug?也许Java10、Junit和SLF4J不能一起工作?在我的模块中-info.java:需要slf4j.api


请帮帮我

当您在ModulePath中添加了外部JAR时,就会发生这种情况。 删除那些添加的外部jar,并使用pom.xml添加依赖项


在Dependency Hierarchy下进行检查,slf4j库应该在一个Dependency下

我相信您已经将slf4j的jar添加到模块路径:


转到Project->BuildPath->Config BuildPath->Remove JAR from Modulepath

需要从spring引导项目中删除module-info.class

在eclipse中的模块路径中只有jdk,在类路径中有其他maven依赖项。在eclipse中的模块路径中只有jdk,在类路径中有其他maven依赖项。