前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring boot with Hessian

Spring boot with Hessian

作者头像
netkiller old
发布2018-03-05 18:12:45
1.2K0
发布2018-03-05 18:12:45
举报
文章被收录于专栏:Netkiller

节选自《Netkiller Java 手札》一书

5.20. Spring boot with Hessian

5.20.1. Maven

代码语言:javascript
复制
		<dependency>
			<groupId>com.caucho</groupId>
			<artifactId>hessian</artifactId>
			<version>4.0.38</version>
		</dependency>			

5.20.2. Application

代码语言:javascript
复制
			package cn.netkiller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
// @EnableMongoRepositories
// @EnableJpaRepositories
@EnableScheduling
public class Application {

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

	}
}			

5.20.3. HessianServiceExporter

代码语言:javascript
复制
			package cn.netkiller.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.caucho.HessianProxyFactoryBean;
//import org.springframework.remoting.caucho.HessianProxyFactoryBean;
import org.springframework.remoting.caucho.HessianServiceExporter;

import cn.netkiller.service.HelloWorldService;

@Configuration
public class HessionConfig {
	@Autowired
	private HelloWorldService helloWorldService;

	@Bean(name = "/HelloWorldService")
	public HessianServiceExporter hessianServiceExporter() {
		HessianServiceExporter exporter = new HessianServiceExporter();
		exporter.setService(helloWorldService);
		exporter.setServiceInterface(HelloWorldService.class);
		return exporter;
	}

	@Bean
	public HessianProxyFactoryBean helloClient() {
		HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
		factory.setServiceUrl("http://localhost:7000/HelloWorldService");
		factory.setServiceInterface(HelloWorldService.class);
		return factory;
	}
}		

5.20.4. Service

代码语言:javascript
复制
			package cn.netkiller.service;

public interface HelloWorldService {
	String sayHello(String name);
}			
代码语言:javascript
复制
			package cn.netkiller.service.impl;

import org.springframework.stereotype.Component;

import cn.netkiller.service.HelloWorldService;

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

5.20.5. RestController

代码语言:javascript
复制
			package cn.netkiller.rest.hession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.netkiller.service.HelloWorldService;

@RestController
@RequestMapping("/public/hession")
public class TestRestController {
	@Autowired
	HelloWorldService helloWorldService;

	@RequestMapping("/hello")
	public String test() {
		return helloWorldService.sayHello("Spring boot with Hessian.");
	}
}		
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-03-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Netkiller 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 节选自《Netkiller Java 手札》一书
  • 5.20. Spring boot with Hessian
    • 5.20.1. Maven
      • 5.20.2. Application
        • 5.20.3. HessianServiceExporter
          • 5.20.4. Service
            • 5.20.5. RestController
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档