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

(0)

相关推荐

  • 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依

  • Tomcat ssl报错Connector attribute SSLCertificateFile must be defined when using SSL with APR解决方法

    今天同事要求帮忙配置tomcat ssl,直接把linux下tomcat配置ssl这篇文章发给他了,没想到他居然说启动tomcat的时候,报Connector attribute SSLCertificateFile must be defined when using SSL with APR的错误,马上跑过去看,原来他的tomcat版本是7.0的,我发给他的是tomcat6的,检查了key,检查了配置文件,因为他直接复制的我发他文章的配置,折腾了2-3个小时,终于把问题给解决了. 系统:wi

  • Linux连接mysql报错:Access denied for user ‘root’@‘localhost’(using password: YES)的解决方法

    前言 最近在linux连接mysql /usr/local/mysql/bin/mysql -uroot -p 输入密码出现Access denied for user 'root'@'localhost'(using password: YES)错误.下面话不多说了,来一起看看详细的解决方法吧 解决办法: 1.先停止mysql 服务 service mysqld stop 2.进入mysql安装目录bin/ 使用safe模式,进行重启: ./mysqld_safe --skip-grant-t

  • spring boot与redis 实现session共享教程

    如果大家对spring boot不是很了解,大家可以参考下面两篇文章. Spring Boot 快速入门教程 Spring Boot 快速入门指南 这次带来的是spring boot + redis 实现session共享的教程. 在spring boot的文档中,告诉我们添加@EnableRedisHttpSession来开启spring session支持,配置如下: @Configuration @EnableRedisHttpSession public class RedisSessi

  • 解决maven启动Spring项目报错的问题

    第一个问题 java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer 出现原因主要是 javax.servlet-api 在运行时将spring容器当成了servlet容器出现类型转换错误. 解决方法: 在pom.xml文件中修改 javax.servlet-a

  • Android报错Error:Could not find com.android.tools.build:gradle:4.1解决办法

    看字面意思,这个问题是Gradle没有对应版本.在搜索引擎没有找到方法之后,尝试自己解决. 有一点很重要,先保证自己的Android Studio是最新的稳定版本! 因为版本更新会修复很多bug,说不定遇到报错就是某个bug引起的. Could not find com.android.tools.build:gradle:3.0.0. 首先,看报错,大概是长这样的: Error:Could not find com.android.tools.build:gradle:4.1. Searche

  • 关于eclipse安装spring插件报错An error occurred while collecting items to be installed...解决方案

    本文以eclipse4.7安装sts3.9.0为例,解决报错 An error occurred while collecting items to be installed session context was:(profile=D__DevelopTools_eclipse_jee-oxygen_eclipse, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). No repos

  • Studio 编译报错:compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.的解决办法

    报错翻译: compileSdkVersion android-24"需要JDK 1.8或更高版本编译. 报错现象如下图: 原因:studio默认选择编译的版本为1.8,而当前jdk环境不是1.8.  解决方法: 1. 在build.gradle中查看编译版本 2.查看studio设置,修改studio设置的jdk设置. 方法一:修改JDK,更改为JDK1.8, 方法二:更改studio编译版本.如下图: 总结 以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价

  • Golang运行报错找不到包:package xxx is not in GOROOT的解决过程

    目录 1 区分几个路径 2 GO111MODULE 3 解决方案 方案一:关闭 go mod 模式 方案二:使用go mod 模式 总结 1 区分几个路径 GOROOT:Golang的安装路径,安装之后就默认自带了 GOPATH:Golang的工作目录 go_project // (go_project为 GOPATH目录)– bin // golang编译可执行文件存放路径– pkg // golang编译包时,生成的.a文件存放路径– src // 源码路径.按照golang默认约定,go

  • spring boot整合redis实现shiro的分布式session共享的方法

    我们知道,shiro是通过SessionManager来管理Session的,而对于Session的操作则是通过SessionDao来实现的,默认的情况下,shiro实现了两种SessionDao,分别为CachingSessionDAO和MemorySessionDAO,当我们使用EhCache缓存时,则是使用的CachingSessionDAO,不适用缓存的情况下,就会选择基于内存的SessionDao.所以,如果我们想实现基于Redis的分布式Session共享,重点在于重写Session

随机推荐