package com.github.dddpaul;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder(Application.class);
        parentBuilder.child(ServiceOneConfiguration.class).properties("server.port:8081").run(args);
        parentBuilder.child(ServiceTwoConfiguration.class).properties("server.port:8082").run(args);
    }

    @Service
    static class SharedService {
        public String getMessage() {
            return "I'm shared service";
        }
    }

    @Configuration
    @EnableAutoConfiguration
    static class ServiceOneConfiguration {
        @Bean
        public ControllerOne controller(SharedService service) {
            return new ControllerOne(service);
        }
    }

    @Configuration
    @EnableAutoConfiguration
    static class ServiceTwoConfiguration {
        @Bean
        public ControllerTwo controller(SharedService service) {
            return new ControllerTwo(service);
        }
    }

    @RequestMapping("/one")
    static class ControllerOne {
        private SharedService service;

        public ControllerOne(SharedService service) {
            this.service = service;
        }

        @RequestMapping
        @ResponseBody
        public String getMessage() {
            return "ControllerOne says \"" + this.service.getMessage() + "\"";
        }
    }

    @RequestMapping("/two")
    static class ControllerTwo {
        private SharedService service;

        public ControllerTwo(SharedService service) {
            this.service = service;
        }

        @RequestMapping
        @ResponseBody
        public String getMessage() {
            return "ControllerTwo says \"" + this.service.getMessage() + "\"";
        }
    }
}

@@ -22,16 +22,79 @@
 dpaul;%0A%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -396,32 +396,82 @@
 .Configuration;%0A
+import org.springframework.stereotype.Controller;%0A
 import org.sprin
@@ -1274,578 +1274,159 @@
    @
-Bean%0A        public ControllerOne controller(SharedService service) %7B%0A            return new ControllerOne(service);%0A        %7D%0A    %7D%0A%0A    @Configuration%0A    @EnableAutoConfiguration%0A    static class ServiceTwoConfiguration %7B%0A        @Bean%0A        public ControllerTwo controller(SharedService service) %7B%0A            return new ControllerTwo(service);%0A        %7D%0A    %7D%0A%0A    @RequestMapping(%22/one%22)%0A    static class ControllerOne %7B%0A        private SharedService service;%0A%0A        public ControllerOne(SharedService service) %7B%0A            this.service = service;%0A        %7D%0A%0A
+Controller%0A        @RequestMapping(%22/one%22)%0A        static class ControllerOne %7B%0A            @Autowired%0A            private SharedService service;%0A%0A    
     
@@ -1445,32 +1445,36 @@
 Mapping%0A        
+    
 @ResponseBody%0A  
@@ -1463,32 +1463,36 @@
   @ResponseBody%0A
+    
         public S
@@ -1516,32 +1516,36 @@
 ) %7B%0A            
+    
 return %22Controll
@@ -1553,37 +1553,32 @@
 rOne says %5C%22%22 + 
-this.
 service.getMessa
@@ -1582,32 +1582,46 @@
 ssage() + %22%5C%22%22;%0A
+            %7D%0A
         %7D%0A    %7D%0A
@@ -1630,184 +1630,239 @@
    @
-RequestMapping(%22/two%22)%0A    static class ControllerTwo %7B%0A        private SharedService service;%0A%0A        public ControllerTwo(SharedService service) %7B%0A            this.s
+Configuration%0A    @EnableAutoConfiguration%0A    static class ServiceTwoConfiguration %7B%0A        @Controller%0A        @RequestMapping(%22/two%22)%0A        static class ControllerOne %7B%0A            @Autowired%0A            private SharedS
 ervice
- =
  ser
@@ -1871,27 +1871,21 @@
 ce;%0A
- 
+%0A
        
-%7D%0A%0A
      
-   
 @Req
@@ -1896,32 +1896,36 @@
 Mapping%0A        
+    
 @ResponseBody%0A  
@@ -1914,32 +1914,36 @@
   @ResponseBody%0A
+    
         public S
@@ -1967,32 +1967,36 @@
 ) %7B%0A            
+    
 return %22Controll
@@ -2016,13 +2016,8 @@
 %22 + 
-this.
 serv
@@ -2033,32 +2033,46 @@
 ssage() + %22%5C%22%22;%0A
+            %7D%0A
         %7D%0A    %7D%0A

Use @Controller annotation instead @Bean