首页 > 解决方案 > Spring Boot 应用程序无法热交换更改

问题描述

我正在开发一个 Spring Boot 项目,我试图将我们的 IDE 从 STS 切换到 Intellij CE。除调试外,一切正常。每当我更改 Java 类时,Spring 都会尝试重新启动整个应用程序并失败并显示以下消息:

web - 2018-09-27 08:39:18,494 [restartedMain] WARN osbceAnnotationConfigEmbeddedWebApplicationContext - 上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“userController”的bean时出错:表示不满足的依赖关系通过字段“userService”;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有“com.xyz.service.IUserService”类型的合格 bean 可用:预计至少有 1 个有资格作为自动装配候选者的 bean。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
web - 2018-09-27 08:39:18,496 [restartedMain] 信息 osojLocalContainerEntityManagerFactoryBean - 为持久性单元“默认”关闭 JPA EntityManagerFactory
web - 2018-09-27 08:39:18,498 [restartedMain] 信息 ocatalina.core.StandardService - 停止服务 [Tomcat]
web - 2018-09-27 08:39:18,524 [restartedMain] 信息 osbalAutoConfigurationReportLoggingInitializer -

启动 ApplicationContext 时出错。要显示自动配置报告,请在启用“调试”的情况下重新运行您的应用程序。
web - 2018-09-27 08:39:18,871 [restartedMain] 错误 osbdLoggingFailureAnalysisReporter -

******************************
应用程序无法启动
******************************

描述:

com.xyz.controller.UserController 中的字段 userService 需要找不到类型为“com.xyz.service.IUserService”的 bean。


行动:

考虑在您的配置中定义“com.xyz.service.IUserService”类型的 bean。

以下是有关环境的一些上下文:

  1. spring-boot-devtools 1.5.9 依赖被添加到我们的 pom.xml
  2. 选中“首选项->构建、执行、部署->编译器->自动构建项目”选项

  3. 我尝试使用选中和未选中的选项“cmd+shift+a->Registry->compiler.automake.allow.when.app.running”进行调试

  4. IDE版本是

    IDE版本

  5. spring-boot-starter-parent 版本是 1.5.9.RELEASE

  6. 以下结构描述了类层次结构:

com.xyz
|-服务
| |-IUserService
| |-实现
| |-用户服务
|-控制器
   |-用户控制器
  1. UserService.java 用 @org.springframework.stereotype.Service 注释
  2. UserController 具有以下字段:
    @自动连线
    私有 IUserService 用户服务

另外,我已经尝试了该线程的所有答案,但未能解决问题。有没有人遇到过这个问题?预期的行为不是重新启动整个应用程序,而是仅热交换已更改的工件。

编辑:

这是 UserController 示例:

@org.springframework.web.bind.annotation.RestController
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController{

    @Autowired
    private IUserService userService;
    ...
}

标签: javaspringspring-bootintellij-idea

解决方案


Spring Boot 运行配置中有一个选项可以在重新启动应用程序上下文之前尝试热交换:

在此处输入图像描述

正确的触发器文件选项将自动添加到命令行。


推荐阅读