No converter found capable of converting from type java.lang.Object to type byte[] in JdbcOperationsSessionRepository

前提是你 提交于 2019-12-23 03:25:04

问题


I am trying to store spring session in oracle Db through spring xml based configuration.

I have manually created the tables (SPRING_SESSION and SPRING_SESSION_ATTRIBUTES) provided in schema-oracle.sql and provided entries in web.xml and session.xml as suggested in spring doc guide: http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession-jdbc-xml.html

jars in WEb-INF/lib/:

spring-web-4.0.2.RELEASE.jar
spring-session-1.2.0.RELEASE.jar
spring-session-jdbc-1.2.0.RELEASE.jar
spring-jdbc-4.0.2.RELEASE.jar

error trace:

JBWEB000236: Servlet.service() for servlet jsp threw exception: org.springframework.core.convert.ConverterNotFoundException: **No converter found capable of converting from type java.lang.Object to type byte[]**
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:291) [spring-core-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:177) [spring-core-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    **at org.springframework.session.jdbc.JdbcOperationsSessionRepository.serialize(JdbcOperationsSessionRepository.java:524) [spring-session-1.2.0.RELEASE.jar:]**
    at org.springframework.session.jdbc.JdbcOperationsSessionRepository.access$200(JdbcOperationsSessionRepository.java:130) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.jdbc.JdbcOperationsSessionRepository$1$2.setValues(JdbcOperationsSessionRepository.java:298) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:997) [spring-jdbc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:987) [spring-jdbc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:642) [spring-jdbc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:671) [spring-jdbc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:987) [spring-jdbc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.session.jdbc.JdbcOperationsSessionRepository$1.doInTransactionWithoutResult(JdbcOperationsSessionRepository.java:290) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:34) [spring-tx-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) [spring-tx-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.session.jdbc.JdbcOperationsSessionRepository.save(JdbcOperationsSessionRepository.java:273) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.jdbc.JdbcOperationsSessionRepository.save(JdbcOperationsSessionRepository.java:130) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.commitSession(SessionRepositoryFilter.java:244) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.access$100(SessionRepositoryFilter.java:214) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryResponseWrapper.onResponseCommitted(SessionRepositoryFilter.java:202) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.OnCommittedResponseWrapper.doOnResponseCommitted(OnCommittedResponseWrapper.java:226) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.OnCommittedResponseWrapper.checkContentLength(OnCommittedResponseWrapper.java:216) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.OnCommittedResponseWrapper.access$200(OnCommittedResponseWrapper.java:37) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.OnCommittedResponseWrapper$SaveContextPrintWriter.write(OnCommittedResponseWrapper.java:281) [spring-session-1.2.0.RELEASE.jar:]
    at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:260) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at java.io.PrintWriter.write(PrintWriter.java:426) [rt.jar:1.7.0_45]
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:309) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at java.io.Writer.write(Writer.java:157) [rt.jar:1.7.0_45]
    at org.apache.jsp.WEB_002dINF.jsp.common.frameworkResource_jsp._jspService(frameworkResource_jsp.java:806)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:832) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:718) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:655) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]
    at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:150) [javamelody-core-1.58.0.jar:1.58.0]
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:286) [javamelody-core-1.58.0.jar:1.58.0]
    at com.sun.proxy.$Proxy222.include(Unknown Source)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:940) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jsp.WEB_002dINF.jsp.loginpage_jsp._jspService(loginpage_jsp.java:128)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:832) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:620) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:553) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:482) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]
    at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:150) [javamelody-core-1.58.0.jar:1.58.0]
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:286) [javamelody-core-1.58.0.jar:1.58.0]
    at com.sun.proxy.$Proxy222.forward(Unknown Source)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:162) [javamelody-core-1.58.0.jar:1.58.0]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:164) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80) [spring-session-1.2.0.RELEASE.jar:]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]

回答1:


I got this working by implementing my own Converter because it seems the one in org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration doesn't load up properly (there's a note in the code about this.)

I got the data to save by creating my own ByteaConversionService based on the what was in JdbcHttpSessionConfiguration.

First create the bean in the xml configuration with a property

<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration">
    <property name="springSessionConversionService">
        <bean class="com.mycompany.ByteaConversionService" />
    </property>
</bean>

And then create the class in the package com.mycompany

public class ByteaConversionService extends GenericConversionService {
    public ByteaConversionService() {
        addConverter(Object.class, byte[].class, new SerializingConverter());
        addConverter(byte[].class, Object.class, new DeserializingConverter());
    }
}

This worked for me. (Now I'm struggling with how to make Multiple Sessions work.)



来源:https://stackoverflow.com/questions/38125977/no-converter-found-capable-of-converting-from-type-java-lang-object-to-type-byte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!