3

I'm trying to build a spring boot (2.6.3) application with java modules (java 17) and gradle(7.4).

right now my folder structure looks like this:

 |- build.gradle.kts |- settings.gradle.kts |- src |- main |- java |- com.my.package |- Application.java |- module-info.java 

my module:

 module com.my.package { requires spring.boot; requires spring.boot.autoconfigure; requires spring.boot.actuator.autoconfigure; opens com.my.package; } 

The application class:

 @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 

I already found out that I had to use opens with my package instead of just using exports. If I where to use exports I would get this error:

java.lang.IllegalAccessException-->module com.my.package does not open com.my.package to unnamed module @1a482e36

Now when I run this with the opens I'll get this error here:

java.lang.IllegalAccessError-->superinterface check failed: class com.my.package.Application$$EnhancerBySpringCGLIB$$917dba7a (in module com.my.package) cannot access class org.springframework.context.annotation.ConfigurationClassEnhancer$EnhancedConfiguration (in unnamed module @0x1623b78d) because module com.my.package does not read unnamed module @0x1623b78d

I've read things about using the -classpath JVM argument. But I am not quite certain which path to put there. And to be frank I am trying to find a solution that works without any arguments that need to be passed. So that the experience is similar to spring without (java)modules.

It'd be great if someone could help me to understand what I am doing wrong here. I'm obviously new to java modules and trying to wrap my head around things.

Thanks in advance!

Cheers, Daniel

2
  • try adding the JVM argument --add-reads com.my.package=ALL-UNNAMED. See this. Or try stackoverflow.com/questions/66660963/… Commented Feb 22, 2022 at 10:20
  • thanks @dan1st that did the trick! Commented Feb 22, 2022 at 11:30

2 Answers 2

1

The module to require for CGLib-related issues spring.aop (that did the trick for me this morning).

I follow on the Original Post (OP) self-answered question because adding --add-reads defeats the whole purpose of using Java Platform Module System (JPMS) in the first place.

Sign up to request clarification or add additional context in comments.

Comments

-2

As dan1st was pointing out --add-reads com.my.package=ALL-UNNAMED did the trick. A more verbose explanation can be found in the question dan1st was sharing I didn't even think of the option that it could be IDE related. (I am using IntelliJ)

1 Comment

It's not IDE related. Nor should this option be used.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.