// ApplicationConfig.java (Your bean configuration class where you set up the beans) @Configuration @PropertySource("classpath:application.properties") // path to property file @ComponentScan(basePackages = "com.examplepackage") // path to the root package to scan for beans by IoC Container public class ApplicationConfig { // No need to define @Bean methods for GreetingService and HelloController // Spring will automatically detect and instantiate beans based on component scanning } // application.properties (Values can also be overriden by run configuration variables(VM/ args/ Config class etc)) app.greeting=Hello, World! // GreetingService.java (The service interface) public interface GreetingService { String greet(); } // GreetingServiceImpl.java (The service implementation) @Service public class GreetingServiceImpl implements GreetingService { @Value("${app.greeting}") // pull data from application.properties file private String greetingMessage; @Override public String greet() { return greetingMessage; } } //HelloController.java (The controller that needs the service dependency) @RestController public class HelloController { private final GreetingService greetingService; @Autowired // the service dependency will be injected here by the IoC Container public HelloController(GreetingService greetingService) { this.greetingService = greetingService; } @GetMapping("/") // API or route to access the service output public String hello() { return greetingService.greet(); } } // Application.java (Main class) @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }