我已经设置了一个基本的 Spring 框架 Web 应用程序,并且开始从基于 XML 的配置切换到使用注释。我的服务器和 Web 客户端位于不同的计算机上,因此我一直使用 Spring HttpInvokerServiceExporter 来启用它们之间的远程处理。
客户:
<bean id="accountService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="${server.url}/AccountService"/>
<property name="serviceInterface" value="com.equinitixanite.knowledgebase.common.service.AccountService"/>
</bean>
服务器:
<bean name="accountService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="accountService"/>
<property name="serviceInterface" value="example.AccountService"/>
我的问题是,如何使用注释获得相同的结果? (我的意思是,如何避免在 XML 中声明每一项服务?)
最佳答案
客户:
@Configuration
public class ClientConfiguration {
@Value("${server.url}")
private String serverUrl;
@Bean
public HttpInvokerProxyFactoryBean httpInvokerProxy() {
HttpInvokerProxyFactoryBean httpInvoker = new HttpInvokerProxyFactoryBean();
httpInvoker.setServiceUrl(serverUrl + "/AccountService");
httpInvoker.setServiceInterface(AccountService.class);
return httpInvoker;
}
}
服务器:
@Configuration
@ComponentScan
public class ServerConfiguration {
@Bean
public HttpInvokerServiceExporter accountServiceExporter(AccountService accountService) {
HttpInvokerServiceExporter httpInvokerServiceExporter =
new HttpInvokerServiceExporter();
httpInvokerServiceExporter.setService(accountService);
httpInvokerServiceExporter.setServiceInterface(AccountService.class);
return httpInvokerServiceExporter;
}
}
关于spring - 如何使用 Spring 注解实现远程处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28887860/