Spring基础

2021-11-08  本文已影响0人  抬头挺胸才算活着
public interface HelloWorldService {
    void sayHi(String name);
}
public class HelloWorldServiceImpl implements HelloWorldService {

    public void sayHi(String message) {
        System.out.println(message);
    }
}
public class HelloWorldServiceClient {

    @Autowired
    private HelloWorldService helloWorld;

    public void showMessage() {
        helloWorld.sayHi("Hello world!");
    }
}
@Configuration
public class AppRunner {

    @Bean
    public HelloWorldService createHelloWorldService() {
    }

    @Bean
    public HelloWorldServiceClient createClient() {
        return new HelloWorldServiceClient();
    }

    public static void main(String... strings) {
        AnnotationConfigApplicationContext context =
                                new AnnotationConfigApplicationContext(AppRunner.class);
        HelloWorldServiceClient bean = context.getBean(HelloWorldServiceClient.class);
        bean.showMessage();
    }

}
上一篇下一篇

猜你喜欢

热点阅读