public class HelloController { public void hello() { System.out.println("Hello, World!"); } } @Component public class AppConfig { @Bean public HelloController helloController() { return new HelloController(); } } @Configuration @EnableWebMvc @ComponentScan(basePackages = "com.example") public class WebConfig implements WebMvcConfigurer { ... } public class Application { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(AppConfig.class, WebConfig.class); context.refresh(); HelloController helloController = context.getBean(HelloController.class); helloController.hello(); } }


上一篇:
下一篇:
切换中文