【发布时间】:2016-04-08 13:09:36
【问题描述】:
我正在关注spring官方教程,为spring boot添加redis session支持。
http://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot.html
pom.xml
...
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
...
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
...
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
...
我没有从 Spring Boot 的1.3.0.RELEASE 开始将版本添加到 Spring 会话中,jar 包含在其中。即使按照教程添加版本1.0.2.RELEASE 也不能解决我的问题
请注意spring-boot 1.3.1.RELEASE,使用的spring版本是4.2.4.RELEASE
配置
@EnableRedisHttpSession
public class HttpSessionConfig {
}
属性文件
#redis
spring.redis.host=127.0.0.1
spring.redis.port=6379
我没有添加密码,因为我的 redis 服务器密码为空。即使添加密码也没有解决我的问题。
当我运行应用程序时,它会给出以下错误
原因:..NoSuchBeanDefinitionException:没有为依赖项找到类型为 [...SessionRepository] 的合格 bean:expect...endency。依赖注释:{}
我还为下面的参考添加了完整的错误堆栈
016-01-05 01:49:50.775 ERROR 7616 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
...
at com.enbiso.proj.estudo.Application.main(Application.java:25) [classes/:na]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
...
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
... 8 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springSessionRepositoryFilter' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.session.SessionRepository]: : No qualifying bean of type [org.springframework.session.SessionRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.session.SessionRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
...
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_20]
at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_20]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.session.SessionRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
...
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 27 common frames omitted
【问题讨论】:
-
发布豆类的文件
-
我没找到你。你想要哪个 bean 文件?与 Redis 相关,我还没有创建任何 bean。我错过了什么吗?
-
在哪里定义这个 bean SessionRepository
-
它没有在我的代码中的任何地方定义。根据spring boot不是应该由框架本身启动吗?
标签: java spring spring-mvc spring-boot spring-session