記一次springBoot+dubbo+hessian搭建服務間文件傳輸的坑

公司的dubbo provider服務是搭建在Tomcat之上的(不是以dubbo的Main.main()運行),項目以web項目方式啓動,引入了hessian之後遠程調用hessian接口提示FileNotfound。。。,這個錯查了下都說是路徑有問題.

這個問題糾結了兩天才得以解決,最後問題是org.apache.dubbo.remoting.http.servlet.DispatcherServlet,這個Servlet沒有進行註冊,springboot web形式的項目需要手動用配置類註冊

這個配置類只配置了hessian,dubbo協議配置在了properties中

import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.remoting.http.servlet.DispatcherServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DubboConfig {

	@Bean(name = "hessian")
	public ProtocolConfig protocolConfig() {
		ProtocolConfig protocolConfig = new ProtocolConfig();
		protocolConfig.setId("hessian");
		protocolConfig.setName("hessian");
		protocolConfig.setPort(8081);
		protocolConfig.setServer("servlet");
		protocolConfig.setContextpath("mysql-demo-provider");
		return protocolConfig;
	}
	
	@Bean
	public ServletRegistrationBean<DispatcherServlet> servletRegistrationBean() {
		return new ServletRegistrationBean<DispatcherServlet>(new DispatcherServlet(), "/*");
	}

}

其他的一些配置和代碼

        <!-- hessian 支持遠程服務間文件傳輸依賴 -->
        <dependency>
		    <groupId>com.caucho</groupId>
		    <artifactId>hessian</artifactId>
		</dependency>

如果多個協議都使用,指定hessian,協議服務提供者指定協議

@Service(interfaceClass = DemoHessianService.class, protocol = "hessian", version = "1.0.0", timeout = 120000)
public class DemoHessianProvider implements DemoHessianService {

	@Override
	public String testSaveFile(String fileName,InputStream nis) {

普通接口指定dubbo協議
 

@Service(interfaceClass = DemoService.class, protocol = "dubbo", version = "1.0.0", timeout = 120000)
public class DemoProvider implements DemoService {

消費者只要引入和提供者一樣的hessian的依賴即可,其他無需配置。

gitee測試項目:https://gitee.com/fxqy/boot-dubbo-demo

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章