So I've got a simple spring boot app, @SpringBootApplication, a stub @Configuration and a @RestController all in the same package. Spring-boot-web-starter is there and the webserver comes up fine, actuator endpoints and all. But I cannot for the life of me get the app to pick up the @RestControllers.
Main.class:
package com.iglossolalia.munin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
 public static void main(String[] args) {
 SpringApplication.run(MuninContext.class, args);
 }
}
MuninContext.class:
package com.iglossolalia.munin;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
public class MuninContext {
}
MuninService.class:
package com.iglossolalia.munin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MuninService {
 private static final Logger LOG = LoggerFactory.getLogger(MuninService.class);
 public MuninService() {
 LOG.info("Started MuninService");
 }
 @GetMapping("/health")
 public String healthCheck() {
 return "pong";
 }
}
Tried explicitly adding the rest controller to the component scan with no luck there.
2 Answers 2
You have no @ComponentScan annotation in your MuninContext. Actually you can write SpringApplication.run(Main.class, args) in main method as Spring Initializr generate by default, you don't really need your context, because @SpringBootApplication work as configuration and contains @EnableAutoConfiguration, @ComponentScan, and some other annotations. Otherwise, as you pass your config class as argument in SpringApplication.run method, annotation @SpringBootApplication in Main class has no effect
Comments
In the MuninService RestController you have defined only a constructor() MuninService(),and added a /health endpoint supporting the actuator, but there are no user defined endpoints defined in the Controller, so even though the service started without issues(as per your comment) there are no endpoints to test the status of Controller.
@ComponentScanfrom@SpringBootApplicationby using your custom bootstrap class.