转 Spring Boot之No session repository could be auto-configured, check your configuration问题解决
1. 环境介绍
JDK 1.8 Spring-Boot 1.5.1.RELEASE, STS IDE
2. 问题的提出
创建了一个非常简约的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的功能分析上。
3. 问题的解决与分析
在网上搜索之后,我们发现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)
转 Spring Boot之No session repository could be auto-configured, check your configuration问题解决的更多相关文章
- spring boot + redis 实现session共享
这次带来的是spring boot + redis 实现session共享的教程. 在spring boot的文档中,告诉我们添加@EnableRedisHttpSession来开启spring se ...
- Spring Boot下如何自定义Repository中的DAO方法
环境配置介绍 jdk 1.8, Spring Boot 1.5.3.RELEASE, Mysql, Spring Data, JPA 问题描述 Spring Data提供了一套简单易用的DAO层抽象与 ...
- spring boot 2.x 系列 —— spring boot 实现分布式 session
文章目录 一.项目结构 二.分布式session的配置 2.1 引入依赖 2.2 Redis配置 2.3 启动类上添加@EnableRedisHttpSession 注解开启 spring-sessi ...
- Spring boot 官网学习笔记 - Auto-configuration(@SpringBootApplication、@EnableAutoConfiguration、@Configuration)
Spring Boot auto-configuration attempts to automatically configure your Spring application based on ...
- Spring Boot+redis存储session,满足集群部署、分布式系统的session共享
本文讲述spring-boot工程中使用spring-session机制进行安全认证,并且通过redis存储session,满足集群部署.分布式系统的session共享. 原文链接:https://w ...
- spring boot 中@Mapper和@Repository的区别
0--前言 @Mapper和@Repository是常用的两个注解,两者都是用在dao上,两者功能差不多,容易混淆,有必要清楚其细微区别: 1--区别 @Repository需要在Spring中配置扫 ...
- 【Kotlin】spring boot项目中,在Idea下启动,报错@Configuration class 'BugsnagClient' may not be final.
报错如下: Exception encountered during context initialization - cancelling refresh attempt: org.springfr ...
- 玩转spring boot——负载均衡与session共享
前言 当项目上线后,如果要修复bug或扩充功能,都需要重启tomcat服务.此时,正在使用应用的用户们就需要等待服务器的重启,而这就会造成不好的用户体验.还有,当仅仅只有一台tomcat服务时,如果 ...
- Java中设置Session过期时间(Spring Boot)
1.Spring Boot: server.session.cookie.comment = #注释会话cookie. server.session.cookie.domain = #会话cookie ...
随机推荐
- 功能WBS分解
小组名称:飞天小女警 项目名称:礼物挑选小工具 小组成员:沈柏杉(组长).程媛媛.杨钰宁.谭力铭 代码地址:HTTPS: https://git.coding.net/shenbaishan/GIFT ...
- 善用Eclipse的代码模板功能
转载自: 善用Eclipse的代码模板功能 Eclipse是个非常强大的IDE,作为一个JAVA程序员,几乎每天都与它打交道,但是它强大的功能都用到了吗? 今天让我们来看一下Eclipse中的“代码模 ...
- 2013长春网赛1005 hdu 4763 Theme Section(kmp应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题意:给出一个字符串,问能不能在该串的前中后部找到相同的子串,输出最长的字串的长度. 分析:km ...
- 小菜菜mysql练习解读分析1——查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数
查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数 好的,第一道题,刚开始做,就栽了个跟头,爽歪歪,至于怎么栽跟头的 ——需要分析题目,查询的是 ...
- Docker一些常用命令
1.启动Docker服务 service docker start 2.查看所有镜像 docker images 3.查看正在运行的容器 docker ps 4.查看所有容器 docker ps -a ...
- java 调用 C# webapi
最近项目需要 java调用 .net 的webapi. 对于get来说很简单,但是post方法遇到了些问题,最后也是曲线救国. 先看代码 Java 代码 public static void ma ...
- 【刷题】BZOJ 3653 谈笑风生
Description 设T 为一棵有根树,我们做如下的定义: ? 设a和b为T 中的两个不同节点.如果a是b的祖先,那么称"a比b不知道 高明到哪里去了". ? 设a 和 b 为 ...
- php中的动态变量的一个应用
原文:https://www.cnblogs.com/JimmyBright/p/9869168.html 某些情况下,可以代替switch语句,大大简化代码,非常有意思哦 $list = [ [ ' ...
- STEM 是个怎样高大上的东西?
近几年来,STEM 教育概念传入中国,并且越来越多地成为家长及教育机构关注的焦点. STEM教育概念同时成为了各大小教育机构及公司宣传造势的赚钱工具,可家长.学生.老师们真的理解究竟何为 STEM/S ...
- 内联汇编_把a值赋给b的汇编代码
int main(int argc, char *argv[]) { int a = 10, b; __asm__("movl %1, %%eax\n\t" "movl ...