Java模块系统-为什么我们需要在-add-modules

时间:2019-04-22 09:20:50

标签: java spring-boot java-11 java-module spring-modules

最近,我正在将Spring Boot(2.1.3版本)的虚拟项目转换为Java 11上的spring boot muti模块项目。为了使其正常工作,我必须显式添加--add-modules=java.instrument作为运行时vm参数。请在Spring boot multi module project with java 11 throws cannot access class org.springframework.cglib.core.ReflectUtils

中找到相关的问题

然后我使用—list-modules检查了已安装的jdk的默认模块,我可以看到 java.instrument中。我想知道为什么我需要显式添加java.instrument?

我在 https://openjdk.java.net/jeps/261 中读到

“有时需要将模块添加到默认根集中,以确保特定的平台,库或服务提供者模块将出现在结果模块图中。在任何阶段都可以选择 --add-modules(,)“ *,但我并不完全理解。

具有Spring / java模块系统专业知识的人能否解释一下为什么即使隐式存在某个模块也必须显式添加一些模块?

[已使用module-info.java和异常更新] 这是springboot模块的module-info.java

open module myModule {
    requires spring.boot.autoconfigure;
    requires spring.context;
    requires spring.boot;
    requires spring.web;
    requires org.jsoup;
}

这是一个例外,我可以看到我是否明确不添加--add-module java.instrument(或需要java.instruement)

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at legalAppFetchModule/run.App.main(App.java:11) ~[classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:125) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:415) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ~[spring-boot-2.1.3.RELEASE.jar:na]
    ... 8 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:921) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:928) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:455) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:106) ~[spring-boot-2.1.3.RELEASE.jar:na]
    ... 13 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during start
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na]
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    ... 21 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:921) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    ... 21 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Error starting the loader
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na]
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    ... 29 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Error starting the loader
    at org.apache.catalina.loader.WebappLoader.startInternal(WebappLoader.java:413) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4980) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    ... 29 common frames omitted
Caused by: java.lang.NoClassDefFoundError: java/lang/instrument/ClassFileTransformer
    at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
    at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3167) ~[na:na]
    at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3192) ~[na:na]
    at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3198) ~[na:na]
    at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3198) ~[na:na]
    at java.base/java.lang.Class.getMethods(Class.java:1905) ~[na:na]
    at org.apache.tomcat.util.modeler.modules.MbeansDescriptorsIntrospectionSource.createManagedBean(MbeansDescriptorsIntrospectionSource.java:298) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.tomcat.util.modeler.modules.MbeansDescriptorsIntrospectionSource.execute(MbeansDescriptorsIntrospectionSource.java:78) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.tomcat.util.modeler.modules.MbeansDescriptorsIntrospectionSource.loadDescriptors(MbeansDescriptorsIntrospectionSource.java:71) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.tomcat.util.modeler.Registry.load(Registry.java:598) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.tomcat.util.modeler.Registry.findManagedBean(Registry.java:504) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.tomcat.util.modeler.Registry.registerComponent(Registry.java:627) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.catalina.loader.WebappLoader.startInternal(WebappLoader.java:408) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    ... 38 common frames omitted
Caused by: java.lang.ClassNotFoundException: java.lang.instrument.ClassFileTransformer
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
    ... 51 common frames omitted

0 个答案:

没有答案