java - Spring Boot 应用程序无法热插拔更改

标签 java spring spring-boot intellij-idea

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

web - 2018-09-27 08:39:18,494 [restartedMain] WARN  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xyz.service.IUserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
web - 2018-09-27 08:39:18,496 [restartedMain] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
web - 2018-09-27 08:39:18,498 [restartedMain] INFO  o.a.catalina.core.StandardService - Stopping service [Tomcat]
web - 2018-09-27 08:39:18,524 [restartedMain] INFO  o.s.b.a.l.AutoConfigurationReportLoggingInitializer - 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
web - 2018-09-27 08:39:18,871 [restartedMain] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field userService in com.xyz.controller.UserController required a bean of type 'com.xyz.service.IUserService' that could not be found.


Action:

Consider defining a bean of type 'com.xyz.service.IUserService' in your configuration.

Here is some context about the environment:

  1. The spring-boot-devtools 1.5.9 dependency is added to our pom.xml
  2. The option "Preferences->Build, Execution, Deployment->Compiler->Build project automatically" is checked

  3. I've tried debug with the option "cmd+shift+a->Registry->compiler.automake.allow.when.app.running" both checked and unchecked

  4. The IDE version is

    IDE version

  5. The spring-boot-starter-parent version is 1.5.9.RELEASE

  6. The following structure describes the class hierarchy:

com.xyz
|-service
|  |-IUserService
|  |-impl
|     |-UserService
|-controller
   |-UserController
  1. UserService.java is annotated with @org.springframework.stereotype.Service
  2. UserController has the following field:
    @Autowired
    private IUserService userService

Also, I've tried all the answers from this thread but didn't manage to solve the problem. Has anyone faced this issue? The expected behavior is not restart the whole application and hot swap only the changed artifacts.

Edit:

Here's the UserController sample:

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

    @Autowired
    private IUserService userService;
    ...
}

最佳答案

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

enter image description here

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

关于java - Spring Boot 应用程序无法热插拔更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52537358/

相关文章:

java - 如何在JPA中有效地截断多对多表?

javascript - 如何在 Spring Boot 中的提交表单中将变量传递给 Controller ​​?

java - 如何在不每 2 秒请求一次的情况下将数据推送到 jsp?

java - org.springframework.beans.NotReadablePropertyException : - dropdown form

java - 如何在 Spring Boot 应用程序的资源文件夹中创建文件夹?

java - JDBC Template异常表或 View 不存在但实际存在

java - 在 JSF2 中显示 list 属性

java - 如何简化 MouseListener 以便我没有所有这些未使用的方法?

spring - Gradle 同步错误 :No service of type StyledTextOutputFactory available in ProjectScopeServices

java - 在 O(n log n) 时间内生成长度为 n 且反转次数为 k 的数组的算法?