当前位置:主页 > java教程 > Spring Boot报错:No session repository could be auto-configured, check your configuration的解决方法

Spring Boot报错:No session repository could be auto-configured, check your configuration如何解决

发布:2019-10-19 23:06:27 155


给大家整理了相关的编程文章,网友辛博学根据主题投稿了本篇教程内容,涉及到spring、boot、session、spring、boot、报错、spring、boot、错误处理、Spring Boot报错:No session repository could be auto-configured, check your configuration的解决方法相关内容,已被438网友关注,下面的电子资料对本篇知识点有更加详尽的解释。

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

本文主要跟大家分享了关于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://stackoverflow.com/questions/38194650/no-session-repository-could-be-auto-configured-check-your-configuration-sessio


参考资料

相关文章

  • Spring Boot 3.0升级指南

    发布:2023-04-11

    这篇文章主要为大家介绍了Spring Boot 3.0升级指南,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪


  • Spring中配置数据源的几种方式

    发布:2023-01-03

    给网友们整理关于Spring的教程,今天小编就为大家分享一篇关于Spring中配置数据源的几种方式,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧


  • 浅析Spring boot 中 logback 配置<springProperty> 读取application.properties 中的属性

    发布:2023-04-08

    这篇文章主要介绍了浅析Spring boot 中 logback 配置<springProperty> 读取application.properties 中的属性,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下


  • SpringCloud Zuul实现动态路由的方法

    发布:2020-01-13

    这篇文章主要介绍了SpringCloud Zuul实现动态路由,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


  • springboot中restful风格请求的使用方法示例

    发布:2023-04-12

    RESTful是一种web软件风格,它不是标准也不是协议,它不一定要采用,只是一种风格,它倡导的是一个资源定位(url)及资源操作的风格,下面这篇文章主要给大家介绍了关于springboot中restful风格请求的使用方法,需要的朋友可以参考下


  • springboot使用mybatis开启事务回滚

    发布:2023-04-14

    本文主要介绍了springboot使用mybatis开启事务回滚,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


  • Spring一步到位精通拦截器

    发布:2023-03-10

    拦截器(Interceptor)是一种动态拦截方法调用的机制,在SpringMVC中动态拦截控制器方法的执行。本文将详细讲讲SpringMVC中拦截器的概念及入门案例,感兴趣的可以尝试一下


  • Spring中使用腾讯云发送短信验证码的实现示例

    Spring中使用腾讯云发送短信验证码的实现示例

    发布:2022-10-08

    为网友们分享了关于Spring的教程,本文主要介绍了Spring 中 使用腾讯云发送短信验证码,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下


网友讨论