欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Spring Boot报错:No session repository could be auto-configured, check your configuration的解决方法

程序员文章站 2023-11-26 23:50:52
本文主要跟大家分享了关于spring boot报错:no session repository could be auto-configured, check your c...

本文主要跟大家分享了关于spring boot报错:no session repository could be auto-configured, check your configuration的解决方法,下面话不多说,来一起看看详细的介绍:

一、环境介绍

jdk 1.8  spring-boot 1.5.1.release, sts ide

二、 问题的提出

创建了一个非常简约的spring boot web application,其中使用了spring-session,具体的maven依赖如下:

 <dependency> 
<groupid>org.springframework.session</groupid> 
<artifactid>spring-session</artifactid> 
lt;/dependency> 

在启动过程中,出现了如下错误信息:

error starting applicationcontext. to display the auto-configuration report re-run your application with 'debug' enabled. 
2017-02-23 17:48:10.710 error 29484 --- [ restartedmain] o.s.boot.springapplication    : application startup failed 
 
org.springframework.beans.factory.beancreationexception: error creating bean with name 'org.springframework.boot.autoconfigure.session.sessionautoconfiguration$sessionrepositoryvalidator': invocation of init method failed; nested exception is java.lang.illegalargumentexception: no session repository could be auto-configured, check your configuration (session store type is 'null') 
 at org.springframework.beans.factory.annotation.initdestroyannotationbeanpostprocessor.postprocessbeforeinitialization(initdestroyannotationbeanpostprocessor.java:137) 
 at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsbeforeinitialization(abstractautowirecapablebeanfactory.java:409) 
 at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1620) 
 at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:555) 
 at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:483) 
 at org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) 
 at org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) 
 at org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) 
 at org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) 
 at org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:761) 
 at org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:866) 
 at org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:542) 
 at org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:122) 
 at org.springframework.boot.springapplication.refresh(springapplication.java:737) 
 at org.springframework.boot.springapplication.refreshcontext(springapplication.java:370) 
 at org.springframework.boot.springapplication.run(springapplication.java:314) 
 at org.springframework.boot.springapplication.run(springapplication.java:1162) 
 at org.springframework.boot.springapplication.run(springapplication.java:1151) 
 at org.rosebird.data.stock.stockdataapplication.main(stockdataapplication.java:10) 
 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.boot.devtools.restart.restartlauncher.run(restartlauncher.java:49) 
caused by: java.lang.illegalargumentexception: no session repository could be auto-configured, check your configuration (session store type is 'null') 
 at org.springframework.util.assert.notnull(assert.java:115) 
 at org.springframework.boot.autoconfigure.session.sessionautoconfiguration$sessionrepositoryvalidator.checksessionrepository(sessionautoconfiguration.java:100) 
 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.beans.factory.annotation.initdestroyannotationbeanpostprocessor$lifecycleelement.invoke(initdestroyannotationbeanpostprocessor.java:366) 
 at org.springframework.beans.factory.annotation.initdestroyannotationbeanpostprocessor$lifecyclemetadata.invokeinitmethods(initdestroyannotationbeanpostprocessor.java:311) 
 at org.springframework.beans.factory.annotation.initdestroyannotationbeanpostprocessor.postprocessbeforeinitialization(initdestroyannotationbeanpostprocessor.java:134) 
 ... 23 common frames omitted 

异常栈很长,关键的错误信息是:no session repository could be auto-configured, check your configuration (session store type is 'null') ,这个信息对于我们进行问题分析提供了非常大的指引, 我们将重点放在session store type的功能分析上。

三、问题的解决与分析

 在网上搜索之后,我们发现session store type使用来存放session的存储方式,目前spring boot中只支持redis方式。 由于本应用暂无需将session放入redis的需求,故这里就可以将session store type设置为none.

这里我们将此配置信息放入application.properites之中:

# default-store in spring session. it will be set in redis only outside. 
spring.session.store-type=none 

重新启动应用,错误信息消失, 我们可以看到了启动正常的信息了:

2017-02-23 19:36:17.437 info 10500 --- [ restartedmain] o.s.s.web.defaultsecurityfilterchain  : creating filter chain: orrequestmatcher [requestmatchers=[ant [pattern='/css/**'], ant [pattern='/js/**'], ant [pattern='/images/**'], ant [pattern='/webjars/**'], ant [pattern='/**/favicon.ico'], ant [pattern='/error']]], [] 
2017-02-23 19:36:17.823 info 10500 --- [ restartedmain] o.s.s.web.defaultsecurityfilterchain  : creating filter chain: orrequestmatcher [requestmatchers=[ant [pattern='/**']]], [org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter@6c7bc3c3, org.springframework.security.web.context.securitycontextpersistencefilter@7e251380, org.springframework.security.web.header.headerwriterfilter@d2c9b20, org.springframework.security.web.authentication.logout.logoutfilter@32d5aa81, org.springframework.security.web.authentication.www.basicauthenticationfilter@57b802cf, org.springframework.security.web.savedrequest.requestcacheawarefilter@6a11f15, org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter@510cb143, org.springframework.security.web.authentication.anonymousauthenticationfilter@69e3d43f, org.springframework.security.web.session.sessionmanagementfilter@182c322e, org.springframework.security.web.access.exceptiontranslationfilter@72545397, org.springframework.security.web.access.intercept.filtersecurityinterceptor@7c8a6e92] 
2017-02-23 19:36:18.163 info 10500 --- [ restartedmain] o.s.b.d.a.optionallivereloadserver  : livereload server is running on port 35729 
2017-02-23 19:36:18.346 info 10500 --- [ restartedmain] o.s.j.e.a.annotationmbeanexporter  : registering beans for jmx exposure on startup 
2017-02-23 19:36:18.570 info 10500 --- [ restartedmain] s.b.c.e.t.tomcatembeddedservletcontainer : tomcat started on port(s): 8080 (http) 
2017-02-23 19:36:18.588 info 10500 --- [ restartedmain] o.r.data.stock.stockdataapplication  : started stockdataapplication in 25.393 seconds (jvm running for 27.444) 

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。

参考资料:

 1. http://*.com/questions/38194650/no-session-repository-could-be-auto-configured-check-your-configuration-sessio