我正在尝试将我的 Java 8 项目升级到 Java 11,并且在这样做时遇到了很多问题,但是我已经解决了所有问题,除了每次尝试运行我的Netbeans 中的项目:
警告:上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“loginDialogFXController”的bean时出错:通过字段“ldapTemplate”表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建 com.decisioninsight.teleios.spring.config.LdapConfig 中定义的名称为“ldapTemplate”的 bean 时出错:通过工厂方法实例化 bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.ldap.core.LdapTemplate]:工厂方法“ldapTemplate”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error created bean with name ' com.decisioninsight.teleios.spring.config.LdapConfig 中定义的 contextSource':通过工厂方法的 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.ldap.core.support.LdapContextSource]:工厂方法 'contextSource' 抛出异常;嵌套异常是 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 无法实例化 [org.springframework.ldap.core.support.LdapContextSource]:工厂方法 'contextSource' 抛出异常;嵌套异常是 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 无法实例化 [org.springframework.ldap.core.support.LdapContextSource]:工厂方法 'contextSource' 抛出异常;嵌套异常是 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
我确实知道此错误的假定解决方案是将 --add-exports 标志添加到此答案中指定的 POM 文件中。这是我的 POM 文件的一部分:
<profile>
<id>default</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<fork>true</fork>
<compilerArgs>
<arg>--add-exports</arg>
<arg>java.naming/com.sun.jndi.ldap=spring.ldap.core</arg>
</compilerArgs>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-cp .</argument>
<argument>--module-path='${project.build.directory}/modules'</argument>
<argument>--module=${moduleName}/${mainClass}</argument>
</arguments>
<longModulepath>false</longModulepath>
<addResourcesToClasspath>true</addResourcesToClasspath>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-libs</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>copy-target</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/modules/${project.build.finalName}.jar</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
然而,每次在 Netbeans 中运行项目时,我仍然会收到此错误。我错过了什么吗?