4

I`m working on a Spring Boot project and I tried to switch our IDE from STS to Intellij CE. Everything is working fine except when debugging. Whenever I change a Java class, the Spring tries to restart the whole application and fail with the following message:

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;
    ...
}
Rafael Sousa
  • 691
  • 5
  • 8
  • is your `UserService` annotated with `@Service`? Could you please extend your question with Class signatures including their annotations? – Hakan Dilek Sep 27 '18 at 12:55
  • Can you start your application at all? Or you are having issues with hot swap feature? – Mladen Savić Sep 27 '18 at 12:58
  • @HakanDilek yes, it is as pointed at the 7th note about the environment. Also, the application starts just fine and processes requests as well. The issue happens when I try to change something when debugging an already executing application. – Rafael Sousa Sep 27 '18 at 14:21
  • Perhaps, you are missing out on any of the annotations, might be `@Controller` or `@RestController` on `UserController` or `@Service` on `UserService` – Nisarg Patil Sep 27 '18 at 14:43
  • Updated the post description. The controller seems properly set. – Rafael Sousa Sep 27 '18 at 15:11
  • Does `UserService` actually implement `IUserService`? e.g. `public class UserService implements IUserService { ...`? – Hasan Can Saral Sep 27 '18 at 20:45
  • Yes, `UserService` does implement `IUserService`. – Rafael Sousa Sep 28 '18 at 13:53

1 Answers1

0

There is an option in the Spring Boot run configuration to try hot swapping before restarting the application context:

enter image description here

The correct trigger file option will automatically be added to the command line.

herman
  • 11,740
  • 5
  • 47
  • 58