使用拼图模块使用jdk9运行spring boot [英] Run spring boot with jdk9 using jigsaw modules

查看:82
本文介绍了使用拼图模块使用jdk9运行spring boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此应用程序有什么问题.我认为类路径jar和模块jar的混合是有效的.对于所有没有显式module-info的jar都变成自动模块了吗?当我删除我的module-info.java时,它可以工作.因为在这种情况下,IDEA使用类路径.

What's wrong with this application. I thought the mix of classpath jars and module jars are valid. For all jars not having an explicit module-info become an automatic module? When I delete my module-info.java it works. Because IDEA using the classpath for this case.

Java(TM)SE运行时环境(内部版本9 + 176)

Java(TM) SE Runtime Environment (build 9+176)

IntelliJ IDEA 2017.1.4

IntelliJ IDEA 2017.1.4

module-info.java

module-info.java

module test {
    requires spring.boot.autoconfigure;
    requires spring.boot;
}

App.java

package com.foo.test;

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

@SpringBootApplication
public class App {

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

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.foo.test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.M2</version>
    </parent>

    <name>test</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.9</maven.compiler.source>
        <maven.compiler.target>1.9</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

线程主"中的异常java.lang.IllegalArgumentException:无法 实例化接口 org.springframework.context.ApplicationContextInitializer: org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:439) 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:418) 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:409) 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.(SpringApplication.java:266) 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.(SpringApplication.java:247) 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) 在test/com.foo.test.App.main(App.java:10)的原因: java.lang.NoClassDefFoundError:java/sql/SQLException 在 spring.beans@5.0.0.RC2/org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:145) 在 spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:435) ... 7更多原因:java.lang.ClassNotFoundException: java.sql.SQLException在 java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) 在 java.base/jdk.internal.loader.ClassLoaders $ AppClassLoader.loadClass(ClassLoaders.java:185) 在java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) ...还有9个

Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:439) at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:418) at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:409) at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.(SpringApplication.java:266) at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.(SpringApplication.java:247) at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) at test/com.foo.test.App.main(App.java:10) Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException at spring.beans@5.0.0.RC2/org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:145) at spring.boot@2.0.0.M2/org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:435) ... 7 more Caused by: java.lang.ClassNotFoundException: java.sql.SQLException at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) ... 9 more

推荐答案

我假设spring.boot是一个自动模块.自动模块没有声明其依赖关系,因此您必须使用--add-modules来确保所有需要的显式模块都得到了解决.如果spring.boot是一个显式模块,那么我认为它将是requires java.sql,并且您不会遇到此问题.

I assume spring.boot is an automatic module. An automatic module doesn't declare it dependences so you have to use --add-modules to ensure that any explicit modules needed are resolved. If spring.boot were an explicit module then I assume it would requires java.sql and you won't have this issue.

这篇关于使用拼图模块使用jdk9运行spring boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆