Reputation: 141
I have a Spring Boot Application which uses Jetty as Web Server, I also use gradle to build the application into executable .jar.
When I run my application with IntelliJ run or debug option, I suddenly get a class cast exception inside one of my controllers:
ClassCastException: com.test.matan.GenericParameter can not be cast into com.test.matan.GenericParameter
Its the same class as you can see. This class is a part of a dependency module of my Application, which I developed.
When I run my application with the executable jar: "java -jar my-app.jar" the same process works just fine, no exceptions and casting works fine as expected.
I came to a conclusion that IntelliJ is in charge of this strange "bug", but I don't understand how can I fix it. Running the application directly from the IDE is much more convenient and easier.
Any ideas? appreciated!
Edit: I use IntelliJ 2017 and can not update for now due to work's network limitations.
Upvotes: 4
Views: 1438
Reputation: 420
This is happening because spring-boot-devtools
has a class loader, but IntelliJ has it's own class loader. Removing spring-boot-devtools
from pom.xml solved this for me.
Also you can just remove it from the libraries list in your project:
Project Settings -> Libraries -> find spring-boot-devtools -> delete
Upvotes: 6
Reputation: 2166
You can try clearing Intellij cache, that often helps with strange bugs like these.
If the problem persists, please check your run configuration and make sure that it's doing the same as java -jar my-app.jar
command.
Upvotes: 0