SpringBoot(2.1.1)整合hessian(十二)

1.首先添加hessian依赖

        <dependency>
            <groupId>com.caucho</groupId>
            <artifactId>hessian</artifactId>
            <version>4.0.38</version>
        </dependency>

2.服务端:HessianServer,端口号:8090

public interface HelloWorldService {
    String sayHello(String name);
}

@Service("HelloWorldService")
public class HelloWorldServiceImpl implements HelloWorldService {
    @Override
    public String sayHello(String name) {
        return "Hello World! " + name;
    }
}

@SpringBootApplication
public class HessianServerApplication {
    @Autowired
    private HelloWorldService helloWorldService;

    public static void main(String[] args) {
        SpringApplication.run(HessianServerApplication.class, args);
    }
    //发布服务
    @Bean(name = "/HelloWorldService")
    public HessianServiceExporter accountService() {
        HessianServiceExporter exporter = new HessianServiceExporter();
        exporter.setService(helloWorldService);
        exporter.setServiceInterface(HelloWorldService.class);
        return exporter;
    }
}

 

3.客户端代码:HessianClient,同服务端一样引入hessian依赖,端口号:8092

 

public interface HelloWorldService {
    String sayHello(String name);
}

启动类

/**
 * @author alen
 * @create 2018-12-03 20:53
 **/
@SpringBootApplication
public class HessianClientApplication {
    @Bean
    public HessianProxyFactoryBean helloClient() {
        HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
        factory.setServiceUrl("http://localhost:8090/HelloWorldService");
        factory.setServiceInterface(HelloWorldService.class);
        return factory;
    }

    public static void main(String[] args) {
        SpringApplication.run(HessianClientApplication.class, args);
    }
}

测试Controller


@RestController
public class TestController {
    @Autowired
    private HelloWorldService helloWorldService;

    @RequestMapping("/test")
    public String test() {
        return helloWorldService.sayHello("Spring boot with Hessian.");
    }
}

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值