2016-12-10 31 views
0

我正在使用Dubbo爲使用spring-data-solr進行文檔搜索創建微服務,我的Dubbo版本是2.5.3,而我的spring-data-solr版本是2.0.5。我導出接口是這樣的:Dubbo無法序列化SolrPageRequest

import edu.whu.irlab.scholarreader.domain.Paper; 
import org.springframework.data.domain.Page; 
import org.springframework.data.domain.Pageable; 
import org.springframework.data.solr.core.query.result.HighlightPage; 
import org.springframework.data.solr.repository.Boost; 
import org.springframework.data.solr.repository.Highlight; 

import java.util.Collection; 

public interface PaperService { 

    Page<Paper> findByTitle(String title, Pageable page); 

    Page<Paper> findByContent(String content, Pageable page); 

    Page<Paper> findByTitleOrAbsText(@Boost(2) String title, String absText, Pageable page); 

    @Highlight 
    HighlightPage<Paper> findByIdIn(Collection<String> id, Pageable page); 

    // @Query(value = "name:?0") 
// @Facet(fields = { "cat" }, limit=20) 
// FacetPage<Paper> findByNameAndFacetOnCategory(String name, Pageable page); 
    Page<Paper> findAll(Pageable pageable); 

    Page<Paper> findByKeywords(String keywords, Pageable pageable); 

    Page<Paper> findByAuthors(String authors, Pageable pageable); 

    Page<Paper> findByAbsText(String absText, Pageable pageable); 

    Page<Paper> findByAffiliations(String affiliations, Pageable pageable); 

    Page<Paper> findBySearchFields(String searchFields, Pageable pageable); 

}

在供應商我實現類:

import edu.whu.irlab.scholarreader.dao.solr.SolrPaperRepository; 
import edu.whu.irlab.scholarreader.domain.Paper; 
import edu.whu.irlab.scholarreader.export.PaperService; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.data.domain.Page; 
import org.springframework.data.domain.Pageable; 
import org.springframework.data.solr.core.query.result.HighlightPage; 
import org.springframework.data.solr.repository.Boost; 

import java.util.Collection; 

public class PaperServiceImpl implements PaperService { 

    @Autowired 
    private SolrPaperRepository solrPaperRepository; 

    public PaperServiceImpl() { 

    } 


    @Override 
    public Page<Paper> findByTitle(String title, Pageable page) { 
     return solrPaperRepository.findByTitle(title, page); 
    } 

    @Override 
    public Page<Paper> findByContent(String content, Pageable page) { 
     return solrPaperRepository.findByContent(content, page); 
    } 

    @Override 
    public Page<Paper> findByTitleOrAbsText(@Boost(2) String title, String absText, Pageable page) { 
     return solrPaperRepository.findByTitleOrAbsText(title, absText, page); 
    } 

    @Override 
    public HighlightPage<Paper> findByIdIn(Collection<String> id, Pageable page) { 
     return solrPaperRepository.findByIdIn(id, page); 
    } 

    @Override 
    public Page<Paper> findAll(Pageable pageable) { 
     return solrPaperRepository.findAll(pageable); 
    } 

    @Override 
    public Page<Paper> findByKeywords(String keywords, Pageable pageable) { 
     return solrPaperRepository.findByKeywords(keywords, pageable); 
    } 

    @Override 
    public Page<Paper> findByAuthors(String authors, Pageable pageable) { 
     return solrPaperRepository.findByAuthors(authors, pageable); 
    } 

    @Override 
    public Page<Paper> findByAbsText(String absText, Pageable pageable) { 
     return solrPaperRepository.findByAbsText(absText, pageable); 
    } 

    @Override 
    public Page<Paper> findByAffiliations(String affiliations, Pageable pageable) { 
     return solrPaperRepository.findByAffiliations(affiliations, pageable); 
    } 

    @Override 
    public Page<Paper> findBySearchFields(String searchFields, Pageable pageable) { 
     return solrPaperRepository.findBySearchFields(searchFields, pageable); 
    } 
} 

在達博消費者當調用paperService.findBySearchFields(searchStr, new PageRequest(pageNumber - 1, pageSize));,發生錯誤:

17:35:18.794 [qtp477643715-33] ERROR 500.jsp - Failed to invoke the method findBySearchFields in the service edu.whu.irlab.scholarreader.export.PaperService. Tried 3 times of the providers [10.129.166.252:20880] (1/1) from the registry 127.0.0.1:2181 on the consumer 10.129.166.252 using the dubbo version 2.4.10. Last error is: Failed to invoke remote method: findBySearchFields, provider: dubbo://10.129.166.252:20880/edu.whu.irlab.scholarreader.export.PaperService?anyhost=true&application=dubbo-consumer&check=false&dubbo=2.4.10&interface=edu.whu.irlab.scholarreader.export.PaperService&methods=findByContent,findByIdIn,findByAuthors,findByAffiliations,findBySearchFields,findByTitleOrAbsText,findByTitle,findByAbsText,findAll,findByKeywords&pid=34732&revision=1.0-SNAPSHOT&side=consumer&timestamp=1481362482218, cause: Fail to decode request due to: RpcInvocation [methodName=findBySearchFields, parameterTypes=[class java.lang.String, interface org.springframework.data.domain.Pageable], arguments=null, attachments={path=edu.whu.irlab.scholarreader.export.PaperService, input=355, dubbo=2.4.10, version=0.0.0}] 
com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method findBySearchFields in the service edu.whu.irlab.scholarreader.export.PaperService. Tried 3 times of the providers [10.129.166.252:20880] (1/1) from the registry 127.0.0.1:2181 on the consumer 10.129.166.252 using the dubbo version 2.4.10. Last error is: Failed to invoke remote method: findBySearchFields, provider: dubbo://10.129.166.252:20880/edu.whu.irlab.scholarreader.export.PaperService?anyhost=true&application=dubbo-consumer&check=false&dubbo=2.4.10&interface=edu.whu.irlab.scholarreader.export.PaperService&methods=findByContent,findByIdIn,findByAuthors,findByAffiliations,findBySearchFields,findByTitleOrAbsText,findByTitle,findByAbsText,findAll,findByKeywords&pid=34732&revision=1.0-SNAPSHOT&side=consumer&timestamp=1481362482218, cause: Fail to decode request due to: RpcInvocation [methodName=findBySearchFields, parameterTypes=[class java.lang.String, interface org.springframework.data.domain.Pageable], arguments=null, attachments={path=edu.whu.irlab.scholarreader.export.PaperService, input=355, dubbo=2.4.10, version=0.0.0}] 
    at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:101) 
    at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:226) 
    at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:72) 
    at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52) 
    at com.alibaba.dubbo.common.bytecode.proxy0.findBySearchFields(proxy0.java) 
    at edu.whu.irlab.scholarreader.web.paper.PaperController.list(PaperController.java:47) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:652) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1317) 
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129) 
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1288) 
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) 
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) 
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) 
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) 
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) 
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) 
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) 
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) 
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) 
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) 
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) 
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) 
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1288) 
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:178) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1288) 
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1288) 
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:443) 
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) 
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:556) 
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227) 
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1044) 
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:372) 
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189) 
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:978) 
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) 
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) 
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154) 
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) 
    at org.eclipse.jetty.server.Server.handle(Server.java:369) 
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:486) 
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:933) 
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:995) 
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644) 
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) 
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) 
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667) 
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) 
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) 
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: com.alibaba.dubbo.remoting.RemotingException: Fail to decode request due to: RpcInvocation [methodName=findBySearchFields, parameterTypes=[class java.lang.String, interface org.springframework.data.domain.Pageable], arguments=null, attachments={path=edu.whu.irlab.scholarreader.export.PaperService, input=355, dubbo=2.4.10, version=0.0.0}] 
    at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:190) 
    at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:110) 
    at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:84) 
    at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:96) 
    at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:144) 
    at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:74) 
    at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75) 
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) 
    at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:53) 
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) 
    at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:48) 
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) 
    at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53) 
    at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:77) 
    ... 72 common frames omitted 

org.springframework.data.domain.PageRequest implements java.io.Serializable,但是org.springframework.data.solr.core.query.SolrPageRequest沒有。 PageRequest自動轉換爲SolrPageRequest。 那麼,我該如何解決這個問題呢?如果像這樣,是否說我不能將我的spring-data-solr服務與Dubbo導出?

回答

1

pageable默認實現類是PageRequest,沒有params構造函數,但是dubbo需要這種方法進行解碼,所以它不能解碼