1

I tried to run the quick start cli example after installing Spring CLI.

https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-installing-spring-boot.html#getting-started-cli-example

On: $ spring run app.groovy

Error:

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

Anyone please guide me.

raghu
  • 95
  • 1
  • 10

2 Answers2

0

I'm not sure if you can have a try:

--add-modules=java.sql

I assume spring.boot is an automatic module. An automatic module doesn't declare it dependences so you have to use --add-modules to ensure that any explicit modules needed are resolved. If spring.boot were an explicit module then I assume it would requires java.sql and you won't have this issue.

The same issue with here

Chao Jiang
  • 483
  • 3
  • 13
0

It'll be because you're running the wrong version of Java for the version of Groovy you have. I currently have Java 11 and Java 8 installed, defaulting to Java 11, but I can switch between them easily with a couple of aliases I have set up. Earlier today I tried running a simple RestController using Spring Boot CLI & got the same error as you. I realised I was running Java 11, switched to 8, re-ran the command, & everything works fine.

Matt Moran
  • 697
  • 1
  • 9
  • 22