## What You Will Learn during this Step: - Lets add a RestController with a dependency and see Spring Boot Magic live ## Theory Break : Quick Spring and Spring MVC Primer - What is dependency? - @Component - @Autowired - @RestController ## Useful Snippets and References ``` package com.in28minutes.springboot; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class WelcomeController { //Auto wiring @Autowired private WelcomeService service; @RequestMapping("/welcome") public String welcome() { return service.retrieveWelcomeMessage(); } } @Component class WelcomeService { public String retrieveWelcomeMessage() { //Complex Method return "Good Morning updated"; } } ``` ## Files List ### pom.xml ``` 4.0.0 com.in28minutes.springboot first-springboot-project 0.0.1-SNAPSHOT org.springframework.boot spring-boot-starter-parent 1.4.0.RELEASE 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-maven-plugin ``` ### src/main/java/com/in28minutes/service/WelcomeService.java ``` package com.in28minutes.service; import org.springframework.stereotype.Component; @Component public class WelcomeService { public String retrieveWelcomeMessage() { //Complex Method return "Good Morning updated"; } } ``` ### src/main/java/com/in28minutes/springboot/Application.java ``` package com.in28minutes.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan("com.in28minutes") public class Application { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); } } ``` ### src/main/java/com/in28minutes/springboot/WelcomeController.java ``` package com.in28minutes.springboot; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.in28minutes.service.WelcomeService; @RestController public class WelcomeController { //Auto wiring @Autowired private WelcomeService service; @RequestMapping("/welcome") public String welcome() { return service.retrieveWelcomeMessage(); } } ```