Create Project: springboot_autowired_manually (add Spring Boot Starters from the table)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside package controllers)
Create Package: services (inside main package)
– Create Class: MyService.java (inside package controllers)
MyController.java
package com.ivoronline.springboot_autowired_manually.controllers;
import com.ivoronline.springboot_autowired_manually.services.MyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
//@Autowired
MyService myService = new MyService();
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
String Results = myService.sayHello();
return Results;
}
}
MyService.java
package com.ivoronline.springboot_autowired_manually.services;
import org.springframework.stereotype.Service;
@Service
public class MyService {
public String sayHello() {
return "Hello";
}
}