<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.xqlee.project</groupId>
<artifactId>demo-springboot-rpc-hessian-server</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<name>demo-springboot-rpc-hessian-server</name>
<description>lee-xqlee-v2.0</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.caucho/hessian -->
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.51</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package net.xqlee.project.service;
public interface HelloWorldService {
String sayHello(String name);
}
HelloWorldServiceServiceImp.java
package net.xqlee.project.service;
import org.springframework.stereotype.Service;
@Service("HelloWorldService")
public class HelloWorldServiceServiceImp implements HelloWorldService {
@Override
public String sayHello(String name) {
return "Hello, " + name;
}
}
package net.xqlee.project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianServiceExporter;
import net.xqlee.project.service.HelloWorldService;
@SpringBootApplication
public class DemoSpringbootRpcHessianApplication {
@Autowired
private HelloWorldService helloWorldService;
public static void main(String[] args) {
SpringApplication.run(DemoSpringbootRpcHessianApplication.class, args);
}
// 发布服务
@Bean(name = "/HelloWorldService")
public HessianServiceExporter accountService() {
HessianServiceExporter exporter = new HessianServiceExporter();
exporter.setService(helloWorldService);
exporter.setServiceInterface(HelloWorldService.class);
return exporter;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.xqlee.project</groupId>
<artifactId>demo-springboot-rpc-hessian-client</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<name>demo-springboot-rpc-hessian-client</name>
<description>lee-xqlee-v2.0</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.caucho/hessian -->
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.51</version>
</dependency>
<!-- 本地引入hessian服务端的接口 -->
<dependency>
<groupId>net.xqlee.project</groupId>
<artifactId>rpc-hessian-demo</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/rpc-hessian-demo-interface.jar</systemPath>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package net.xqlee.project;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianProxyFactoryBean;
import net.xqlee.project.service.HelloWorldService;
@SpringBootApplication
public class DemoSpringbootRpcHessianClientApplication {
public static void main(String[] args) {
SpringApplication.run(DemoSpringbootRpcHessianClientApplication.class, args);
}
@Bean
public HessianProxyFactoryBean helloClient() {
HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
factory.setServiceUrl("http://localhost:8083/HelloWorldService");
factory.setServiceInterface(HelloWorldService.class);
return factory;
}
}
package net.xqlee.project.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import net.xqlee.project.service.HelloWorldService;
@RestController
public class DemoHessianController {
@Autowired
HelloWorldService helloWorldService;
@GetMapping("/rpchello.do")
public Object rpcSayHello(String name) {
return helloWorldService.sayHello(name);
}
}
http://blog.xqlee.com/article/294.html