重启Springboot项目时发生“ java.lang.LinkageError:违反加载器约束:”错误

时间:2018-11-23 02:31:37

标签: java spring spring-boot

我有一个简单的Springboot project

我在IntelliJ IDE中进行了设置:

  1. 在注册表中启用compiler.automake.allow.when.app.running复选框
  2. 在编译器设置中启用Build project automatically

在更改代码并保存时,并非总是如此,但经常出现错误:

2018-11-23 05:25:10.544 ERROR 344 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "ru.krivochenko.demo.user.UserService.getNewUser()Lru/krivochenko/demo/user/User;" the class loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @6ce6e730 (instance of org.springframework.boot.devtools.restart.classloader.RestartClassLoader, child of 'app' jdk.internal.loader.ClassLoaders$AppClassLoader) of the current class, ru/krivochenko/demo/MainController, and the class loader 'app' (instance of jdk.internal.loader.ClassLoaders$AppClassLoader) for the method's defining class, ru/krivochenko/demo/user/UserService, have different Class objects for the type ru/krivochenko/demo/user/User used in the signature] with root cause

Full stack trace

感谢帮助!

1 个答案:

答案 0 :(得分:1)

由于某种原因,在重建更改的类后,在它真正存在之前会有时间间隔。 我在application.properties中使用了一些值,发现结果对我有用:

spring.devtools.restart.poll-interval=3000 spring.devtools.restart.quiet-period=2999