首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用拼图模块用jdk9运行弹簧引导

使用拼图模块用jdk9运行弹簧引导
EN

Stack Overflow用户
提问于 2017-07-04 16:37:58
回答 4查看 4.2K关注 0票数 7

这个应用程序有什么问题。我认为类路径罐和模块罐的混合是有效的。对于所有没有显式模块的jars来说-信息变成了一个自动模块?当我删除我的模块-info.java时,它可以工作。因为这个案子使用类路径的想法。

Java(TM) SE运行时环境(build 9+176)

IntelliJ IDEA 2017.1.4

module-info.java

代码语言:javascript
复制
module test {
    requires spring.boot.autoconfigure;
    requires spring.boot;
}

App.java

代码语言:javascript
复制
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

代码语言:javascript
复制
<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>

线程"main“中的异常:无法实例化接口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:418).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),由: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多个原因是: java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582):java.sql.SQLException at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) .9

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-07-05 11:33:56

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

票数 7
EN

Stack Overflow用户

发布于 2017-07-05 08:47:14

最后,我拿到了.我的模块信息必须是这样的:

代码语言:javascript
复制
module test {
    requires java.sql; // my real problem solved with this
    requires spring.boot.autoconfigure;
    requires spring.boot;
    exports com.foo.test; // subsequent error 1: beeing accessible for some spring modules
    opens com.foo.test to spring.core; // subsequent error 2: beeing accessible for spring.core in a deep reflection way
}

当我不使用java.sql时,有人能解释为什么我需要在我自己的模块中要求它吗?

票数 5
EN

Stack Overflow用户

发布于 2020-09-01 11:43:01

从Java 8升级到Java 11时,我也遇到了同样的问题。

通过在Intellij运行配置中选择不同的选项解决了问题:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44910768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档