标签分类 技术文章:
当前位置:首页 > 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如何解决

  • 发布时间:
  • 作者:码农之家原创
  • 点击:146

这篇文章主要知识点是关于spring、boot、session、spring、boot、报错、spring、boot、错误处理、的内容,如果大家想对相关知识点有系统深入的学习,可以参阅以下电子书

深入浅出Spring Boot 2.x
  • 类型:Spring大小:257.67 MB格式:PDF出版:人民邮电出版社作者:杨开振
立即下载

更多Java相关的学习资源可以参阅 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的解决方法,下面话不多说,来一起看看详细的介绍:

一、环境介绍

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

以上就是本次给大家分享的关于Java的全部知识点内容总结,大家还可以在下方相关文章里找到java实现的密码强度检测功、 java实现杨辉三角两种输出、 java中jvm虚拟机栈的作用总、 等java文章进一步学习,感谢大家的阅读和支持。

上一篇:Java用POI解析excel并获取所有单元格数据的方法整理

下一篇:spring boot集成rabbitmq的代码实例

展开 +

收起 -

学习笔记
网友NO.916119

SpringBoot 错误处理机制与自定义错误处理实现详解

【1】SpringBoot的默认错误处理 ① 浏览器访问 请求头如下: ② 使用“PostMan”访问 { "timestamp": 1529479254647, "status": 404, "error": "Not Found", "message": "No message available", "path": "/aaa1"} 请求头如下: 总结:如果是浏览器访问,则SpringBoot默认返回错误页面;如果是其他客户端访问,则默认返回JSON数据。 【2】默认错误处理原理 SpringBoot默认配置了许多xxxAutoConfiguration,这里我们找ErrorMvcAutoConfiguration。 其注册部分组件如下: ① DefaultErrorAttributes @Bean@ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)public DefaultErrorAttributes errorAttributes() { return new DefaultErrorAttributes();} 跟踪其源码如下: public class DefaultErrorAttributes implements ErrorAttributes, HandlerExceptionResolver, Ordered { private static final String ERROR_ATTRIBUTE = DefaultErrorAttributes.class.getName() + ".ERROR"; @Override public int getOrder() { return Ordered.HIGHEST_PRECEDENCE; } @Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { storeErrorAttributes(request, ex); return null; } private void storeErrorAttributes(HttpServletRequest request, Exception ex) { request.setAttribute(ERROR_ATTRIBUTE, ex); } @Override public MapString, Object getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) { MapString, Object error……

网友NO.211648

spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)

创建项目 使用IDEA创建一个spring-boot项目,依赖选上 web, validation, freemarker 即可 先看看效果 创建实体类 创建并加上注解,代码如下 public class Person implements Serializable { @NotNull @Length(min = 3, max = 10) // username长度在3-10之间 private String username; @NotNull @Min(18) // 年龄最小要18岁 private Integer age; @NotNull // 使用正则来验证字段,message: 设置验证失败的信息 @Pattern(regexp = "[\\w-\\.]+@([\\w-]+\\.)+[a-z]{2,3}", message = "邮箱格式不正确") private String email; public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; }} 配置controller 代码: @Controllerpublic class WebController extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { //添加一个路由并设置页面名字 registry.addViewController("/results").setViewName("results"); } @GetMapping("/") public String showForm(Person person) { return "form"; } @PostMapping("/") public String checkPersonInfo(@Valid Person person, BindingResult bindingResult, RedirectAttributes redirectAttributes) { // 使用BindingResult来验证表单数据的正确性 if (bindingResult.hasErrors()) { // 将提交的表单内容原封不动……

网友NO.508911

SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)

pom.xml增加依赖包 dependency groupIdio.springfox/groupId artifactIdspringfox-swagger2/artifactId version2.2.2/version /dependency dependency groupIdio.springfox/groupId artifactIdspringfox-swagger-ui/artifactId version2.2.2/version /dependency 编写swapper2配置类 package com.zyank;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import springfox.documentation.builders.ApiInfoBuilder;import springfox.documentation.builders.PathSelectors;import springfox.documentation.builders.RequestHandlerSelectors;import springfox.documentation.service.ApiInfo;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket;import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration@EnableSwagger2public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.zyank.web")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo(){ return new ApiInfoBuilder() .title("Spring Boot中试用Swagger2构建的RESTful APIs") .description("更多Spring Boot相关文章请关注:http://blog.didispace.com/") .termsOfServiceUrl("http://blog.didispace.com/") .contact("leo") .version("1.0") .build(); }} Controller内使用 package com.zyank.web;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.……

网友NO.302780

SpringBoot错误处理机制以及自定义异常处理详解

上篇文章我们讲解了使用Hibernate Validation来校验数据,当校验完数据后,如果发生错误我们需要给客户返回一个错误信息,因此这节我们来讲解一下SpringBoot默认的错误处理机制以及如何自定义异常来处理请求错误。 一、SpringBoot默认的错误处理机制 我们在发送一个请求的时候,如果发生404 SpringBoot会怎么处理呢?我们来发送一个不存在的请求来验证一下看看页面结果。如下所示: 当服务器内部发生错误的时候,页面会返回什么呢? @GetMapping("/user/{id:\\d+}") public User get(@PathVariable String id) { throw new RuntimeException(); } 我们会发现无论是发生什么错误,SpringBoot都会返回一个状态码以及一个错误页面,这个错误页面是怎么来的呢? 我们来看看SpringBoot错误处理模块的源码就会非常清楚,默认的发生错误,它会将请求转发到BasicErrorController控制器来处理请求,下面是该controller类的源码: @Controller@RequestMapping("${server.error.path:${error.path:/error}}")public class BasicErrorController extends AbstractErrorController { private final ErrorProperties errorProperties; /** * Create a new {@link BasicErrorController} instance. * @param errorAttributes the error attributes * @param errorProperties configuration properties */ public BasicErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) { this(errorAttributes, erro……

<
1
>

Copyright 2018-2019 xz577.com 码农之家

版权责任说明