java.lang.ClassCastException: class ... is in unnamed module of loader 'app' - spring-boot-dev-tools
Asked Answered
V

4

6

We have a larger Spring boot application which causes the following exeception:

    java.lang.ClassCastException: class jpa.XVersion cannot be cast to class jpa.XVersion (jpa.XVersion is in unnamed module of loader 'app'; jpa.XVersion is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @671ef14f)
    at y.package.abc(XService.java:70)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)

while starting from within IDEA IntelliJ in relationship with JPA classes.

The application works fine while starting from plain command line.

After we have removed the dependency

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <optional>true</optional>
</dependency>

The execution from within the IDE works fine without any issues.

We are using:

  • Idea IntelliJ 2020.1.2
  • Spring Boot Version 2.3.1,
  • JDK 11.0.7 (Adopt Open JDK),
  • Apache Maven 3.6.3

Does someone has already observed that kind of issue? Does exist a different solution then removing the dependency?

Vapory answered 25/6, 2020 at 12:50 Comment(5)
I faced the same problem, after restart the IDE and cleaning maven it was automatically fixedTee
In IntelliJ idea can you please try Invalidate Cache and restart from file menu.Esquire
Do you use Java 9 modules? It can be related to this: e.g. if there is a valid Java 9 module IDE places their classes into a module path instead of a classpath. If you can reproduce it in a sample project please feel free to file an issue at youtrack.jetbrains.com/issues/IDEA with the reproducer.Striction
@Striction No I don't use any modules (no module-info.java) in our project. That's the weird thing about that.Vapory
I have the same problem using Spring Quartz and Blaze Persistence. Restart class loader might fail with some libraries: docs.spring.io/spring-boot/docs/current/reference/htmlsingle/…Dmitri
E
1

Disable the spring dev tools restart

You can disable the restart feature using the spring.devtools.restart.enabled property set to false. In most cases you can set this in your application.properties (this will still initialize the restart classloader but it won’t watch for file changes).

If you need to completely disable restart support, for example, because it doesn’t work with a specific library, you need to set a System property before calling SpringApplication.run(…​).

For example:

 public static void main(final String[] args) {
    System.setProperty("spring.devtools.restart.enabled", "false");
    SpringApplication.run(Application.class, args);
}

Reference spring docs

Everyday answered 31/3, 2021 at 9:26 Comment(0)
T
0

I removed the dependency below and it worked.

org.springframework.boot spring-boot-devtools runtime true
Trojan answered 26/10, 2020 at 13:46 Comment(0)
T
0

I had the same issue and after invalidating the cache and restart, it worked for me.

Tunicate answered 11/5, 2023 at 1:24 Comment(0)
B
0

If you are using MyBatis like me, you may need to check if the resultMap or resultType in xxx-mapper.xml is compatible with your target type.

This solution works for me. :-)

Balsamic answered 19/11, 2023 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.