public interface RemoteService { public String getRemoteData(); } public class RemoteServiceImpl implements RemoteService { public String getRemoteData() { } } @Configuration public class AppConfig { @Bean public RemoteService remoteService() { return new RemoteServiceImpl(); } } public class RemoteServiceClient { @Autowired private RemoteService remoteService; public void doSomething() { String data = remoteService.getRemoteData(); } } public class MainApplication { public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); RemoteServiceClient client = context.getBean(RemoteServiceClient.class); client.doSomething(); } }


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