0

Is there any way to integrate the auto-restart function of Spring boot devtools with the ActiveJDBC's instrumentation function?

There is also a need to provide instrumentation every time there is a change in the model or DB, but the code generated when there was a Auto-Restart on the devtools side of Spring boot was generated by the instrumentation on the ActiveJDBC side asynchrony with the code occurs, and even if it is the same class on the source, it will not match and will give an error that it can not be cast.

eg.

class dev.logue.sample.models.User cannot be cast to class dev.logue.sample.models.User (dev.logue.sample.models.User is in unnamed module of loader 'app'; dev.logue.sample.models.User is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader

I'm not very familiar with Java, is there any way to synchronize this process?

My Environment:

openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment Zulu11.37+17-CA (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.37+17-CA (build 11.0.6+10-LTS, mixed mode)
Logue
  • 29
  • 4
  • Why not instrument during the build? You still need to compile, correct? – ipolevoy Mar 30 '20 at 23:26
  • I think that an error has occurred such that the class cannot be cast even though it is the same class in the above error message. – Logue Mar 31 '20 at 01:02
  • are you restarting the process after instrumentation? – ipolevoy Apr 01 '20 at 18:43
  • Yes. However, when I modify the other code, Spring devtools reloads, which eventually results in the above error. If it is impossible to cast the same class, I think that it may be due to the mismatch between the binary generated by Spring and the binary generated by ActiveJDBC's Instrument. – Logue Apr 03 '20 at 03:25
  • No, the real reason is because different instances of the class are loaded by different class loaders. The same class loaded with different class loaders is viewed by a JVM as different classes. I'm not familiar with SpringBoot, but I think that is the cause of the problem. Do you have the same issue when you just restart the process? – ipolevoy Apr 03 '20 at 17:59
  • Yes. A similar problem occurred after turning off the automatic restart function of spring devtools. Since there is no help for it, I am dealing with what should be `User user = new User ();` by using `var user = new User ();`. However, unique methods defined in the model class (User class) cannot be used. – Logue Apr 06 '20 at 01:09
  • so that you know, the latest version of ActiveJDBC was released for Java 8. – ipolevoy Apr 07 '20 at 03:16
  • Does the suffix of version "-j8" not mean that it can be used with Java8, but does it mean that it is only for Java8? – Logue Apr 08 '20 at 02:20
  • If your model classes are in src/main/java, they are already on the restart classlaoder. What you need to do is to bring ActiveJDBC on it or maybe there is a bug in ActiveJDBC. See https://stackoverflow.com/questions/33955542/a-dozer-map-exception-related-to-spring-boot-devtools/33969984 for an example – Stephane Nicoll Apr 08 '20 at 08:27

1 Answers1

0

Was self resolved.

Apparently, spring-devtools.properties should explicitly load the class generated by ActiveJDBC.

src/main/resources/META-INF/spring-devtools.properties:

restart.include.activejdbc=/activejdbc-[\\w\\d-\.]+\.jar

The error message did not include activejdbc, so I thought it was related to the class file generated after instrumentation.

Also, just in case, model classes are omitted from Spring devtools scan path in application.properties.

src/main/resources/application.properties:

spring.devtools.restart.additional-exclude=src/main/java/dev/logue/sample/models/**
Logue
  • 29
  • 4