spring - 如何使用 Spring 注解实现远程处理?

标签 spring service frameworks annotations remoting

我已经设置了一个基本的 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/

相关文章:

javascript - Angular5 服务不发送数据?

c# - 检查未注册/丢失的服务

ios - 如何为您的 Swift 框架私下导入第 3 方框架

java - Autowiring 在 Junit 测试和 spring @configuration 中失败

java - 无法保存 spring JPA 与数据库 : Could not set field value by reflection: [. ..] 的多对多关系,根本原因是 java.lang.NullPointerException

model-view-controller - spring mvc @requestmapping 最佳实践

c# - 如何强制我在 Visual Studio 2013 中的项目始终以管理员身份运行?

yii - 如何使用 Yii CGridView 在 2 行中显示单个记录?

java开源从xml生成sql查询

java - 使用 Redis 创建名称为 'enableRedisKeyspaceNotificationsInitializer' 的 bean 时出错