<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.10</version>
</dependency>
</dependencies>
@Configuration
public class AppConfig {
@Bean
public HelloWorldService helloWorldService() {
return new HelloWorldServiceImpl();
}
@Bean
public HelloController helloController() {
return new HelloController(helloWorldService());
}
}
public class MainApp {
public static void main(String[] args) {
ApplicationContext context =
new AnnotationConfigApplicationContext(AppConfig.class);
HelloController controller = context.getBean(HelloController.class);
controller.sayHello();
}
}