Spring 9中的Java 9拆分包错误

时间:2017-10-16 14:15:25

标签: java spring spring-boot java-9 java-module

我得到了很多"拆分包"当我在SpringBoot代码中引入java 9模块时出错。它们无处不在,例如:

Error:java: the unnamed module reads package org.bson.types from both bson and mongodb.driver
Error:java: the unnamed module reads package org.bson.io from both bson and mongodb.driver
Error:java: the unnamed module reads package org.bson from both bson and mongodb.driver
Error:java: the unnamed module reads package com.mongodb.client.model from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package com.mongodb.client from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package com.mongodb from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package org.aopalliance.aop from both aopalliance.repackaged and spring.aop
...

我尝试过很多不同版本,包括1.5.3.RELEASE2.0.0.M52.0.0.BUILD-SNAPSHOT

当maven接受所有依赖项并将其添加为"自动模块"时,问题似乎就出现了。在模块路径上。许多依赖项都有重复的包,这在java 9中是不允许的。错误依赖的示例是spring.aop:5.0.1.BUILD-SNAPSHOT,它显然打包org.aopalliance.aop

SpringBoot定义了所有依赖项。我甚至尝试使用spring initializr中的vanilla项目,仅添加:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>

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

此外,我添加了一个module-info.java来使代码符合java 9:

├── src
│   ├── main
│   │   ├── java
│   │   │   ├── com
│   │   │   │   └── example
│   │   │   │       └── demo
│   │   │   │           └── DemoApplication.java
│   │   │   └── module-info.java
│

这不会编译。

问题: 有没有人有一个SpringBoot项目的工作示例,其中代码是用java 9模块组织的?

0 个答案:

没有答案