我在安装Spring CLI后尝试运行快速启动cli示例。
开:$ spring run app.groovy
错误:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (jar:file:/home/dvraghu15/.install/spring-1.5.9.RELEASE/lib/spring-boot-cli-1.5.9.RELEASE.jar!/BOOT-INF/lib/groovy-2.4.13.jar!/) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.springframework.boot.cli.app.SpringApplicationLauncher.launch(SpringApplicationLauncher.java:65)
at org.springframework.boot.cli.command.run.SpringApplicationRunner$RunThread.run(SpringApplicationRunner.java:173)
Caused by: java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:413)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:383)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:249)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:225)
... 6 more
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:409)
... 10 more
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader.findClass(ExtendedGroovyClassLoader.java:84)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
... 12 more
任何人都请指导我。
答案 0 :(得分:0)
我不确定你是否可以尝试一下:
--add-modules=java.sql
我认为spring.boot是一个自动模块。自动模块不会声明它依赖,因此您必须使用--add-modules
来确保解析所需的任何显式模块。如果spring.boot是一个显式模块,那么我认为它需要java.sql并且你不会遇到这个问题。
与here
相同的问题答案 1 :(得分:0)
这是因为您运行的Java版本与您所拥有的Groovy版本错误。我目前安装了Java 11和Java 8,默认为Java 11,但是我可以使用已设置的几个别名轻松地在它们之间切换。今天早些时候,我尝试使用Spring Boot CLI运行一个简单的RestController并遇到与您相同的错误。我意识到我正在运行Java 11,将其切换为8,重新运行该命令,一切正常。