• Spring boot配合Spring session(redis)遇到的错误


    背景:本MUEAS项目,一开始的时候,是没有引入redis的,考虑到后期性能的问题而引入。之前没有引用redis的时候,用户登录是正常的。但是,在加入redis支持后,登录就出错!错误如下:

      1   .   ____          _            __ _ _
      2  /\ / ___'_ __ _ _(_)_ __  __ _    
      3 ( ( )\___ | '_ | '_| | '_ / _` |    
      4  \/  ___)| |_)| | | | | || (_| |  ) ) ) )
      5   '  |____| .__|_| |_|_| |_\__, | / / / /
      6  =========|_|==============|___/=/_/_/_/
      7  :: Spring Boot ::        (v1.2.7.RELEASE)
      8 
      9 [2015-12-29 10:18:37.165] log4j - 31595  INFO [main] --- Application: Starting Application on CloudGame with PID 31595 (/home/webWps/mueas-mongo/target/classes started by root in /home/webWps/mueas-mongo)
     10 [2015-12-29 10:18:37.237] log4j - 31595  INFO [main] --- AnnotationConfigEmbeddedWebApplicationContext: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7c271d34: startup date [Tue Dec 29 10:18:37 CST 2015]; root of context hierarchy
     11 [2015-12-29 10:18:39.868] log4j - 31595  INFO [main] --- AutowiredAnnotationBeanPostProcessor: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
     12 [2015-12-29 10:18:40.163] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$99932978] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     13 [2015-12-29 10:18:40.419] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [class org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$525eef57] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     14 [2015-12-29 10:18:40.449] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'objectPostProcessor' of type [class org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     15 [2015-12-29 10:18:40.451] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@2cd84149' of type [class org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     16 [2015-12-29 10:18:40.476] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'mueasPermissionEvaluator' of type [class com.tinguish.mueas.infra.security.MueasPermissionEvaluator] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     17 [2015-12-29 10:18:40.540] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'methodSecurityConfig' of type [class com.tinguish.mueas.infra.security.MethodSecurityConfig$$EnhancerBySpringCGLIB$$5242b1ec] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     18 [2015-12-29 10:18:40.557] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'methodSecurityMetadataSource' of type [class org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     19 [2015-12-29 10:18:40.562] log4j - 31595  INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'metaDataSourceAdvisor' of type [class org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
     20 [2015-12-29 10:18:41.039] log4j - 31595  INFO [main] --- TomcatEmbeddedServletContainer: Tomcat initialized with port(s): 8080 (http)
     21 [2015-12-29 10:18:41.449] log4j - 31595  INFO [main] --- StandardService: Starting service Tomcat
     22 [2015-12-29 10:18:41.451] log4j - 31595  INFO [main] --- StandardEngine: Starting Servlet Engine: Apache Tomcat/8.0.28
     23 [2015-12-29 10:18:41.657] log4j - 31595  INFO [localhost-startStop-1] --- [/]: Initializing Spring embedded WebApplicationContext
     24 [2015-12-29 10:18:41.657] log4j - 31595  INFO [localhost-startStop-1] --- ContextLoader: Root WebApplicationContext: initialization completed in 4423 ms
     25 [2015-12-29 10:18:44.031] log4j - 31595  INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/css/**'], []
     26 [2015-12-29 10:18:44.031] log4j - 31595  INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/js/**'], []
     27 [2015-12-29 10:18:44.031] log4j - 31595  INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/images/**'], []
     28 [2015-12-29 10:18:44.031] log4j - 31595  INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/**/favicon.ico'], []
     29 [2015-12-29 10:18:44.031] log4j - 31595  INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/error'], []
     30 [2015-12-29 10:18:44.138] log4j - 31595  INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@272b811d, org.springframework.security.web.context.SecurityContextPersistenceFilter@1ab55f98, org.springframework.security.web.header.HeaderWriterFilter@7da7fe14, org.springframework.security.web.authentication.logout.LogoutFilter@296758e5, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@55ac5e8a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@28facd93, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@74f4c543, org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter@4031202, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@1929ab02, org.springframework.security.web.session.SessionManagementFilter@615a1d5f, org.springframework.security.web.access.ExceptionTranslationFilter@1468193e, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@273c59de]
     31 [2015-12-29 10:18:44.155] log4j - 31595  INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/**']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5f8f81db, org.springframework.security.web.context.SecurityContextPersistenceFilter@165973f5, org.springframework.security.web.header.HeaderWriterFilter@723a02aa, org.springframework.security.web.authentication.logout.LogoutFilter@60c20fb6, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@6495a75a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@4acbe549, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@103a41fc, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@469681e0, org.springframework.security.web.session.SessionManagementFilter@3e85217c, org.springframework.security.web.access.ExceptionTranslationFilter@45c69c37, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@3470e41a]
     32 [2015-12-29 10:18:44.471] log4j - 31595  INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'characterEncodingFilter' to: [/*]
     33 [2015-12-29 10:18:44.471] log4j - 31595  INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
     34 [2015-12-29 10:18:44.472] log4j - 31595  INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'springSessionRepositoryFilter' to: [/*]
     35 [2015-12-29 10:18:44.472] log4j - 31595  INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'springSecurityFilterChain' to: [/*]
     36 [2015-12-29 10:18:44.472] log4j - 31595  INFO [localhost-startStop-1] --- ServletRegistrationBean: Mapping servlet: 'dispatcherServlet' to [/]
     37 [2015-12-29 10:18:44.838] log4j - 31595  INFO [main] --- RequestMappingHandlerAdapter: Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7c271d34: startup date [Tue Dec 29 10:18:37 CST 2015]; root of context hierarchy
     38 [2015-12-29 10:18:44.926] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/userid],methods=[POST]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.userId(com.tinguish.mueas.user.model.User,java.lang.String)
     39 [2015-12-29 10:18:44.926] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/pri_college]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.userPriCollege(com.tinguish.mueas.user.model.User)
     40 [2015-12-29 10:18:44.927] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/sec_college]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.userSecCollege(com.tinguish.mueas.user.model.User)
     41 [2015-12-29 10:18:44.927] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/check/oldPassword]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.checkOldPassword(com.tinguish.mueas.user.model.User,java.lang.String)
     42 [2015-12-29 10:18:44.927] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.mySetting(com.tinguish.mueas.user.model.User)
     43 [2015-12-29 10:18:44.927] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/m_single]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.createSingleUser()
     44 [2015-12-29 10:18:44.927] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/m_multi]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.createMultiUsers()
     45 [2015-12-29 10:18:44.928] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/m_mgmt]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.mgmtUsers(com.tinguish.mueas.user.model.User)
     46 [2015-12-29 10:18:44.928] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/new/one]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.createUser(javax.servlet.http.HttpServletRequest)
     47 [2015-12-29 10:18:44.928] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/profile]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.userProfile(com.tinguish.mueas.user.model.User)
     48 [2015-12-29 10:18:44.928] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/username],methods=[POST]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.userName(com.tinguish.mueas.user.model.User,java.lang.String)
     49 [2015-12-29 10:18:44.929] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/password]}" onto public java.util.Map<java.lang.String, java.lang.String> com.tinguish.mueas.user.controller.UserController.userPassword(com.tinguish.mueas.user.model.User,java.lang.String,java.lang.String)
     50 [2015-12-29 10:18:44.929] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/ || /home]}" onto public java.lang.String com.tinguish.mueas.infra.login.LoginController.home()
     51 [2015-12-29 10:18:44.930] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/seeu]}" onto public java.lang.String com.tinguish.mueas.infra.login.LoginController.logout()
     52 [2015-12-29 10:18:44.930] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/login]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.infra.login.LoginController.login(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
     53 [2015-12-29 10:18:44.931] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/forgot],methods=[POST]}" onto public java.lang.String com.tinguish.mueas.infra.password.ForgotPasswordController.forgetPassword(com.tinguish.mueas.user.model.User,org.springframework.ui.Model) throws javax.mail.MessagingException,java.io.IOException
     54 [2015-12-29 10:18:44.931] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/forgot],methods=[GET]}" onto public java.lang.String com.tinguish.mueas.infra.password.ForgotPasswordController.resetPasswordView(org.springframework.ui.Model)
     55 [2015-12-29 10:18:44.932] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/reset],methods=[GET]}" onto public java.lang.String com.tinguish.mueas.infra.password.ResetPasswordController.resetpasswordView(java.lang.String,org.springframework.ui.Model)
     56 [2015-12-29 10:18:44.932] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/reset],methods=[POST]}" onto public java.lang.String com.tinguish.mueas.infra.password.ResetPasswordController.resetPassword(java.lang.String,com.tinguish.mueas.user.model.User,org.springframework.ui.Model)
     57 [2015-12-29 10:18:44.932] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/error]}" onto org.springframework.web.servlet.ModelAndView com.tinguish.mueas.infra.error.MueasErrorController.error(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
     58 [2015-12-29 10:18:44.933] log4j - 31595  INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/mgmt/score/ || /mgmt/score]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.score.ScoreMgmtController.Score()
     59 [2015-12-29 10:18:44.992] log4j - 31595  INFO [main] --- SimpleUrlHandlerMapping: Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
     60 [2015-12-29 10:18:44.993] log4j - 31595  INFO [main] --- SimpleUrlHandlerMapping: Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
     61 [2015-12-29 10:18:45.090] log4j - 31595  INFO [main] --- SimpleUrlHandlerMapping: Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
     62 [2015-12-29 10:18:45.544] log4j - 31595  INFO [main] --- AnnotationMBeanExporter: Registering beans for JMX exposure on startup
     63 [2015-12-29 10:18:45.554] log4j - 31595  INFO [main] --- DefaultLifecycleProcessor: Starting beans in phase 2147483647
     64 [2015-12-29 10:18:45.757] log4j - 31595  INFO [main] --- TomcatEmbeddedServletContainer: Tomcat started on port(s): 8080 (http)
     65 [2015-12-29 10:18:45.760] log4j - 31595  INFO [main] --- Application: Started Application in 8.99 seconds (JVM running for 9.316)
     66 [2015-12-29 10:21:41.487] log4j - 31595  INFO [http-nio-8080-exec-1] --- [/]: Initializing Spring FrameworkServlet 'dispatcherServlet'
     67 [2015-12-29 10:21:41.488] log4j - 31595  INFO [http-nio-8080-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization started
     68 [2015-12-29 10:21:41.507] log4j - 31595  INFO [http-nio-8080-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization completed in 19 ms
     69 [2015-12-29 10:21:41.690] log4j - 31595  INFO [http-nio-8080-exec-2] --- TemplateEngine: [THYMELEAF] INITIALIZING TEMPLATE ENGINE
     70 [2015-12-29 10:21:41.765] log4j - 31595  INFO [http-nio-8080-exec-2] --- AbstractTemplateResolver: [THYMELEAF] INITIALIZING TEMPLATE RESOLVER: org.thymeleaf.templateresolver.TemplateResolver
     71 [2015-12-29 10:21:41.765] log4j - 31595  INFO [http-nio-8080-exec-2] --- AbstractTemplateResolver: [THYMELEAF] TEMPLATE RESOLVER INITIALIZED OK
     72 [2015-12-29 10:21:41.766] log4j - 31595  INFO [http-nio-8080-exec-2] --- AbstractMessageResolver: [THYMELEAF] INITIALIZING MESSAGE RESOLVER: org.thymeleaf.spring4.messageresolver.SpringMessageResolver
     73 [2015-12-29 10:21:41.766] log4j - 31595  INFO [http-nio-8080-exec-2] --- AbstractMessageResolver: [THYMELEAF] MESSAGE RESOLVER INITIALIZED OK
     74 [2015-12-29 10:21:41.775] log4j - 31595  INFO [http-nio-8080-exec-2] --- CONFIG: [THYMELEAF] TEMPLATE ENGINE CONFIGURATION:
     75 [THYMELEAF] * Cache Factory implementation: org.thymeleaf.cache.StandardCacheManager
     76 [THYMELEAF] * Template modes:
     77 [THYMELEAF]     * VALIDXML
     78 [THYMELEAF]     * HTML5
     79 [THYMELEAF]     * VALIDXHTML
     80 [THYMELEAF]     * LEGACYHTML5
     81 [THYMELEAF]     * XHTML
     82 [THYMELEAF]     * XML
     83 [THYMELEAF] * Template resolvers (in order):
     84 [THYMELEAF]     * org.thymeleaf.templateresolver.TemplateResolver
     85 [THYMELEAF] * Message resolvers (in order):
     86 [THYMELEAF]     * org.thymeleaf.spring4.messageresolver.SpringMessageResolver
     87 [THYMELEAF] * Dialect [1 of 3]: org.thymeleaf.spring4.dialect.SpringStandardDialect
     88 [THYMELEAF]     * Prefix: "th"
     89 [THYMELEAF] * Dialect [2 of 3]: org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect
     90 [THYMELEAF]     * Prefix: "sec"
     91 [THYMELEAF] * Dialect [3 of 3]: nz.net.ultraq.thymeleaf.LayoutDialect
     92 [THYMELEAF]     * Prefix: "layout"
     93 [THYMELEAF] TEMPLATE ENGINE CONFIGURED OK
     94 [2015-12-29 10:21:41.775] log4j - 31595  INFO [http-nio-8080-exec-2] --- TemplateEngine: [THYMELEAF] TEMPLATE ENGINE INITIALIZED
     95 [2015-12-29 10:21:50.834] log4j - 31595 ERROR [http-nio-8080-exec-10] --- [dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
     96 org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: com.tinguish.mueas.user.model.User
     97     at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:52)
     98     at org.springframework.data.redis.core.AbstractOperations.rawHashValue(AbstractOperations.java:146)
     99     at org.springframework.data.redis.core.DefaultHashOperations.putAll(DefaultHashOperations.java:128)
    100     at org.springframework.data.redis.core.DefaultBoundHashOperations.putAll(DefaultBoundHashOperations.java:85)
    101     at org.springframework.session.data.redis.RedisOperationsSessionRepository$RedisSession.saveDelta(RedisOperationsSessionRepository.java:409)
    102     at org.springframework.session.data.redis.RedisOperationsSessionRepository$RedisSession.access$000(RedisOperationsSessionRepository.java:331)
    103     at org.springframework.session.data.redis.RedisOperationsSessionRepository.save(RedisOperationsSessionRepository.java:211)
    104     at org.springframework.session.data.redis.RedisOperationsSessionRepository.save(RedisOperationsSessionRepository.java:141)
    105     at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.commitSession(SessionRepositoryFilter.java:193)
    106     at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.access$100(SessionRepositoryFilter.java:169)
    107     at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:127)
    108     at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:65)
    109     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    110     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    111     at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    112     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    113     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    114     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    115     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
    116     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    117     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    118     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    119     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
    120     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    121     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    122     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    123     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    124     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    125     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    126     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    127     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
    128     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    129     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    130     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    131     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    132     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    133     at java.lang.Thread.run(Thread.java:745)
    134 Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: com.tinguish.mueas.user.model.User
    135     at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:68)
    136     at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:35)
    137     at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:50)
    138     ... 36 more
    139 Caused by: java.io.NotSerializableException: com.tinguish.mueas.user.model.User
    140     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
    141     at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
    142     at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
    143     at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
    144     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
    145     at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
    146     at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
    147     at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
    148     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
    149     at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
    150     at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
    151     at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
    152     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
    153     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
    154     at org.springframework.core.serializer.DefaultSerializer.serialize(DefaultSerializer.java:46)
    155     at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:63)
    156     ... 38 more
    View Code

    很是奇怪。。。。。。

    后来拜读了一下spring data redis的官方文档:

    From the framework perspective, the data stored in Redis is just bytes. While Redis itself supports various types, for the most part these refer to the way the data is stored rather then what it represents. It is up to the user to decide whether the information gets translated into Strings or any other objects. The conversion between the user (custom) types and raw data (and vice-versa) is handled in Spring Data Redis through the RedisSerializer interface (package org.springframework.data.redis.serializer) which as the name implies, takes care of the serialization process. Multiple implementations are available out of the box, two of which have been already mentioned before in this documentation: the StringRedisSerializer and the JdkSerializationRedisSerializer. However one can use OxmSerializer for Object/XML mapping through Spring 3 OXM support or either JacksonJsonRedisSerializer, Jackson2JsonRedisSerializer or `GenericJackson2JsonRedisSerializer for storing data in JSON format. Do note that the storage format is not limited only to values - it can be used for keys, values or hashes without any restrictions.

    从中得到一点启发,那就是spring session redis将session存入到redis后,是将数据序列化后存入的,所以,当没有序列化的数据,直接从数据库读出来,在经过spring security认证之后,会将SecurityContext写入到httpSesson中.

    org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper中saveContext的操作,将会把SecurityContext以SPRING_SECURITY_CONTEXT为key写入httpSession中,而SecurityContext中包含了authentication (UsernamePasswordAuthenticationToken),这个,我相信大家都知道了,这个里面就含有当前登录操作的principle,即继承于UserDetails。

    出于这个考虑,结合错误提示信息Caused by: java.io.NotSerializableException: com.tinguish.mueas.user.model.User,于是将我的User类,改为下面的形式:

    1

     1 //注意,我的User继承BasicUser,所以,只将BasicUser继承Serializable。
     2 public class BasicUser implements Serializable{
     3 
     4     /**
     5      * 
     6      */
     7     private static final long serialVersionUID = -8366929034564774130L;
     8 
     9        。。。。。。。。。。。。。
    10 }

    经过上面的简单修改后,果然,可以正常的登录了,不再出现上述错误,一切操作都正常!

    正常运行下的redis的session下的内容可以看到:

    127.0.0.1:6379> hkeys spring:session:sessions:f5a6f5fa-0d8a-4250-87bd-ca6a82384fe2
    1) "sessionAttr:SPRING_SECURITY_SAVED_REQUEST"
    2) "sessionAttr:SPRING_SECURITY_CONTEXT"
    3) "maxInactiveInterval"
    4) "creationTime"
    5) "lastAccessedTime"
    6) "sessionAttr:SPRING_SECURITY_LAST_EXCEPTION"

     

  • 相关阅读:
    结对编程2
    结对编程总结:简单的四则运算生成程序
    我的结对项目心得与代码规范
    一个团队和他们的调查表-----("调查表与调查结果分析"心得体会)
    目标?我定好了!(我的软件工程课目标)
    Jmeter响应数据为乱码的处理
    软件工程课程建议
    结对编程之Fault、Error、Failure
    我的结对项目编程感想
    调查问卷后的心得
  • 原文地址:https://www.cnblogs.com/shihuc/p/5086520.html
Copyright © 2020-2023  润新知