1

我正在尝试编写一个可以使用 Java 9 运行的简单 Spring Boot 应用程序。我无法在 jdk9 下编译此应用程序。我在日志记录模块周围遇到一堆错误

有没有人有任何在 jdk9 jigsaw 概念下使用 Springboot 的示例应用程序?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project JigsawTest: Compilation failure: Compilation failure: 
[ERROR] the unnamed module reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.aop reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.context reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.beans reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.core reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.web reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.jcl reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.boot.starter.web reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.boot.starter reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.boot.starter.logging reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module logback.classic reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module logback.core reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module slf4j.api reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module jcl.over.slf4j reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module jul.to.slf4j reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module log4j.over.slf4j reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.boot.starter.tomcat reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module tomcat.embed.core reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module tomcat.embed.el reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module tomcat.embed.websocket reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module hibernate.validator reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module validation.api reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module jboss.logging reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module classmate reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module jackson.databind reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module jackson.annotations reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module jackson.core reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.webmvc reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.expression reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.boot reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j
[ERROR] module spring.boot.autoconfigure reads package org.apache.commons.logging from both spring.jcl and jcl.over.slf4j

这是我在 github 中的示例项目的链接

4

2 回答 2

2

看起来像:

  1. 所有的 JAR 都在模块路径上(奇怪)
  2. spring.jcljcl.over.slf4j包含很多相同的包

如果您无法修复 1.,请尝试通过排除两个工件之一来解决 2.。

于 2017-08-09T22:57:38.310 回答
2

我能够在这里编译示例。此时mvn clean package使用 Maven 3.5.0 工作。请注意,我没有尝试运行该应用程序。

请注意,我进行了以下更改:

按照惯例,源代码现在位于与模块名称匹配的文件夹中。

~/com.allstate.jigsaw/src/main/java/...

module-info.java文件已被简化:

module com.allstate.jigsaw {
    requires java.logging;

    requires spring.boot;
}

此外,pom.xml已修改为使用 Java 9。pom.xml根目录中有一个父级,模块文件夹中有另一个。这是主要的依赖,在com.allstate.jigsaw/pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.5.6.RELEASE</version>
</dependency>
于 2017-08-10T10:13:53.413 回答