gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:19:21 25 4
gpt4 key购买 nike

我正在做一个 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:
    @Autowiredprivate 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com