首先除了spring的依赖,还需要加上 hessian的依赖
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.51</version>
</dependency>
其次是要注意注册映射的时候,映射的bean的id并不是实现类的id,而是HessianServiceExporter类型的bean的id。比如,我的实现类的名称是spittleServiceImpl,HessianServiceExporter 的名称是hessianServiceExporter(默认是方法名),这里应该写的是hessianServiceExporter
@Bean
public HessianServiceExporter hessianServiceExporter(SpittleService service) {
HessianServiceExporter exporter=new HessianServiceExporter();
exporter.setService(service);
exporter.setServiceInterface(SpittleService.class);
return exporter;
}
@Bean(name="spittleServiceImpl")
public SpittleService spittleServiceImpl() {
return new SpittleServiceImpl();
}
@Bean
public HandlerMapping hessianMapping() {
SimpleUrlHandlerMapping mapping=new SimpleUrlHandlerMapping();
Properties properties=new Properties();
//hessianExportSpitterService是HessionServiceExporter类型的bean的id
properties.setProperty("/spittle.service","**hessianServiceExporter**");
mapping.setMappings(properties);
return mapping;
}