我正在做一个 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:
- The spring-boot-devtools 1.5.9 dependency is added to our pom.xml
The option "Preferences->Build, Execution, Deployment->Compiler->Build project automatically" is checked
I've tried debug with the option "cmd+shift+a->Registry->compiler.automake.allow.when.app.running" both checked and unchecked
The IDE version is
The spring-boot-starter-parent version is 1.5.9.RELEASE
The following structure describes the class hierarchy:
com.xyz |-service | |-IUserService | |-impl | |-UserService |-controller |-UserController
- UserService.java is annotated with @org.springframework.stereotype.Service
- 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;
...
}
最佳答案
关于java - Spring Boot 应用程序无法热插拔更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52537358/