问题描述
主 java 模块有这种问题.
<上一页>rg.springframework.beans.factory.beancreationexception:在类路径资源[org/springframework/boot/autoconfigure/ldap/embedded/embeddedldapautoconfiguration.class]中定义名称为ldapcontextsource"的bean创建错误:通过工厂方法进行的bean实例化失败;嵌套异常是 org.springframework.beans.beaninstantiationexception:无法实例化 [org.springframework.ldap.core.support.ldapcontextsource]:工厂方法ldapcontextsource"抛出异常;嵌套异常是 java.lang.illegalaccesserror: class org.springframework.ldap.core.support.abstractcontextsource (in module spring.ldap.core) cannot access class com.sun.jndi.ldap.ldapctxfactory (in module java.naming) 因为模块 java.naming 不会将 com.sun.jndi.ldap 导出到模块 spring.ldap.core在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.constructorresolver.instantiate(constructorresolver.java:656) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:636) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1338) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1177) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:557) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:517) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractbeanfactory.lambda$dogetbean$0(abstractbeanfactory.java:323) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:321) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:202) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:879) ~[spring-beans-5.2.2.release.jar:na]在 spring.context@5.2.2.release/org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:878) ~[spring-context-5.2.2.release.jar:na]在 spring.context@5.2.2.release/org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:550) ~[spring-context-5.2.2.release.jar:na]在 spring.boot@2.2.2.release/org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.refresh(servletwebserverapplicationcontext.java:141) ~[spring-boot-2.2.2.release.jar:na]在 spring.boot@2.2.2.release/org.springframework.boot.springapplication.refresh(springapplication.java:747) ~[spring-boot-2.2.2.release.jar:na]在 spring.boot@2.2.2.release/org.springframework.boot.springapplication.refreshcontext(springapplication.java:397) ~[spring-boot-2.2.2.release.jar:na]在 spring.boot@2.2.2.release/org.springframework.boot.springapplication.run(springapplication.java:315) ~[spring-boot-2.2.2.release.jar:na]在 app/com.test.app.app.main(app.java:9) ~[classes/:na]原因:org.springframework.beans.beaninstantiationexception:无法实例化[org.springframework.ldap.core.support.ldapcontextsource]:工厂方法'ldapcontextsource'抛出异常;嵌套异常是 java.lang.illegalaccesserror: class org.springframework.ldap.core.support.abstractcontextsource (in module spring.ldap.core) cannot access class com.sun.jndi.ldap.ldapctxfactory (in module java.naming) 因为模块 java.naming 不会将 com.sun.jndi.ldap 导出到模块 spring.ldap.core在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:185) ~[spring-beans-5.2.2.release.jar:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.constructorresolver.instantiate(constructorresolver.java:651) ~[spring-beans-5.2.2.release.jar:na]...省略了17个常用框架原因:java.lang.illegalaccesserror:类 org.springframework.ldap.core.support.abstractcontextsource(在模块 spring.ldap.core 中)无法访问类 com.sun.jndi.ldap.ldapctxfactory(在模块 java.naming 中)因为模块 java.naming 不会将 com.sun.jndi.ldap 导出到模块 spring.ldap.core在 spring.ldap.core@2.3.2.release/org.springframework.ldap.core.support.abstractcontextsource.(abstractcontextsource.java:77) ~[spring-ldap-core-2.3.2.release.jar:na]在 spring.boot.autoconfigure@2.2.2.release/org.springframework.boot.autoconfigure.ldap.embedded.embeddedldapautoconfiguration.ldapcontextsource(embeddedldapautoconfiguration.java:93) ~[spring-boot-autoconfigure-2.2.2.release.jar:无]在 java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:na]在 java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) ~[na:na]在 java.base/jdk.internal.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:na]在 java.base/java.lang.reflect.method.invoke(method.java:566) ~[na:na]在 spring.beans@5.2.2.release/org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:154) ~[spring-beans-5.2.2.release.jar:na]...省略了18个常用框架进程以退出代码 1 结束我知道出了什么问题,但是除了从主模块中删除 module-info.java 之外,还有什么解决方法吗?
百家乐凯发k8的解决方案
如果你确实理解了错误,详细阅读以下内容:
<块引用>模块 java.naming 不会将 com.sun.jndi.ldap 导出到模块spring.ldap.core
然后,您可以为此制定解决方法,以通过命令行使用修饰符作为 jvm 选项提供访问:
--add-exports java.naming/com.sun.jndi.ldap=spring.ldap.core
had this kind of problem with main java module.
rg.springframework.beans.factory.beancreationexception: error creating bean with name 'ldapcontextsource' defined in class path resource [org/springframework/boot/autoconfigure/ldap/embedded/embeddedldapautoconfiguration.class]: bean instantiation via factory method failed; nested exception is org.springframework.beans.beaninstantiationexception: failed to instantiate [org.springframework.ldap.core.support.ldapcontextsource]: factory method 'ldapcontextsource' threw exception; nested exception is java.lang.illegalaccesserror: class org.springframework.ldap.core.support.abstractcontextsource (in module spring.ldap.core) cannot access class com.sun.jndi.ldap.ldapctxfactory (in module java.naming) because module java.naming does not export com.sun.jndi.ldap to module spring.ldap.core at spring.beans@5.2.2.release/org.springframework.beans.factory.support.constructorresolver.instantiate(constructorresolver.java:656) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:636) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1338) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1177) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:557) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:517) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractbeanfactory.lambda$dogetbean$0(abstractbeanfactory.java:323) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:321) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:202) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:879) ~[spring-beans-5.2.2.release.jar:na] at spring.context@5.2.2.release/org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:878) ~[spring-context-5.2.2.release.jar:na] at spring.context@5.2.2.release/org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:550) ~[spring-context-5.2.2.release.jar:na] at spring.boot@2.2.2.release/org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.refresh(servletwebserverapplicationcontext.java:141) ~[spring-boot-2.2.2.release.jar:na] at spring.boot@2.2.2.release/org.springframework.boot.springapplication.refresh(springapplication.java:747) ~[spring-boot-2.2.2.release.jar:na] at spring.boot@2.2.2.release/org.springframework.boot.springapplication.refreshcontext(springapplication.java:397) ~[spring-boot-2.2.2.release.jar:na] at spring.boot@2.2.2.release/org.springframework.boot.springapplication.run(springapplication.java:315) ~[spring-boot-2.2.2.release.jar:na] at app/com.test.app.app.main(app.java:9) ~[classes/:na] caused by: org.springframework.beans.beaninstantiationexception: failed to instantiate [org.springframework.ldap.core.support.ldapcontextsource]: factory method 'ldapcontextsource' threw exception; nested exception is java.lang.illegalaccesserror: class org.springframework.ldap.core.support.abstractcontextsource (in module spring.ldap.core) cannot access class com.sun.jndi.ldap.ldapctxfactory (in module java.naming) because module java.naming does not export com.sun.jndi.ldap to module spring.ldap.core at spring.beans@5.2.2.release/org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:185) ~[spring-beans-5.2.2.release.jar:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.constructorresolver.instantiate(constructorresolver.java:651) ~[spring-beans-5.2.2.release.jar:na] ... 17 common frames omitted caused by: java.lang.illegalaccesserror: class org.springframework.ldap.core.support.abstractcontextsource (in module spring.ldap.core) cannot access class com.sun.jndi.ldap.ldapctxfactory (in module java.naming) because module java.naming does not export com.sun.jndi.ldap to module spring.ldap.core at spring.ldap.core@2.3.2.release/org.springframework.ldap.core.support.abstractcontextsource.(abstractcontextsource.java:77) ~[spring-ldap-core-2.3.2.release.jar:na] at spring.boot.autoconfigure@2.2.2.release/org.springframework.boot.autoconfigure.ldap.embedded.embeddedldapautoconfiguration.ldapcontextsource(embeddedldapautoconfiguration.java:93) ~[spring-boot-autoconfigure-2.2.2.release.jar:na] at java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:na] at java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:na] at java.base/java.lang.reflect.method.invoke(method.java:566) ~[na:na] at spring.beans@5.2.2.release/org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:154) ~[spring-beans-5.2.2.release.jar:na] ... 18 common frames omitted process finished with exit code 1
i understand whats wrong, but is there any workaround for this, besides remove module-info.java from main module ?
百家乐凯发k8的解决方案
if you do understand the error specifically when it reads in details the following:
module java.naming does not export com.sun.jndi.ldap to module spring.ldap.core
you can then formulate the workaround for this to provide access using modifiers as jvm options via the command line:
--add-exports java.naming/com.sun.jndi.ldap=spring.ldap.core