java - 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。
以下是有关环境的一些上下文:
- spring-boot-devtools 1.5.9 依赖被添加到我们的 pom.xml
选中“首选项->构建、执行、部署->编译器->自动构建项目”选项
我尝试使用选中和未选中的选项“cmd+shift+a->Registry->compiler.automake.allow.when.app.running”进行调试
IDE版本是
spring-boot-starter-parent 版本是 1.5.9.RELEASE
以下结构描述了类层次结构:
com.xyz |-服务 | |-IUserService | |-实现 | |-用户服务 |-控制器 |-用户控制器
- UserService.java 用 @org.springframework.stereotype.Service 注释
- UserController 具有以下字段:
@自动连线 私有 IUserService 用户服务
另外,我已经尝试了该线程的所有答案,但未能解决问题。有没有人遇到过这个问题?预期的行为不是重新启动整个应用程序,而是仅热交换已更改的工件。
编辑:
这是 UserController 示例:
@org.springframework.web.bind.annotation.RestController
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController{
@Autowired
private IUserService userService;
...
}
解决方案
推荐阅读
- spring-boot - 使用 deleteBy 的 Spring 数据 JPA 表达式
- node.js - 如何在 Mongoose/MongoDb 中传递可选参数
- string - 无法在 OCaml 4.05 中修剪字符串(字节)
- vue.js - VueX 没有检测到变化
- ubuntu - 无法登录 Ubuntu 20.04 LTS
- reactjs - react.js - 为什么要渲染两次
- node.js - 部署后Nodejs不会在heroku上启动
- aws-lambda - 我可以知道如何关闭 AWS Lambda 函数的调试日志记录吗?
- javascript - 无法开始 twilio 视频聊天 - Rails
- angular - Angular - FontAwesome 依赖项丢失错误