英文:
No session repository could be auto-configured(session store type is 'redis')
问题
我正在按照这个链接上的Spring Security教程的第三部分进行学习。我需要使用Redis来处理会话信息并交给资源后端。
这是我的application.yml文件:
server:
port: 9000
security:
sessions: NEVER
spring:
session:
store-type: redis
redis:
host: localhost
port: 6379
logging:
level:
org.springframework:
security: DEBUG
session: TRACE
另外,我使用HeaderHttpSessionStrategy bean作为会话策略:
@Bean
HeaderHttpSessionStrategy sessionStrategy() {
return new HeaderHttpSessionStrategy();
}
我的pom.xml文件无法找到相关的类声明,导致出现以下错误:
package org.springframework.session.web.http does not exist
这是我的pom.xml文件:
<properties>
<java.version>14</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我是Spring和Spring Security领域的新手。有没有人能够提供解决这个问题的建议?
编辑:
在pom.xml中添加了新的依赖后:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
我解决了上面的问题,但这次出现了新问题,它说:
No session repository could be auto-configured, check your configuration (session store type is 'redis')
我的Redis配置在application.yml中已经设置。我正在使用Docker上的Redis。我的Docker配置如下:
redis:
image: redis
ports:
- "6379:6379"
英文:
I am following the spring security tutorial from this link on that tutorial third part. I have to use redis to hand away session information to resource backend.
Here my applicaiton.yml file:
server:
port: 9000
security:
sessions: NEVER
spring:
session:
store-type: redis
redis:
host: localhost
port: 6379
logging:
level:
org.springframework:
security: DEBUG
session: TRACE
Also, I use HeaderHttpSessionStrategy bean as a session strategy
@Bean
HeaderHttpSessionStrategy sessionStrategy() {
return new HeaderHttpSessionStrategy();
}
My pom couldn't find the related class declaration and give me
package org.springframework.session.web.http does not exist
Above error Here my pom.xml file.
<properties>
<java.version>14</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I am new in spring and spring-security world. Can any advice solve this problem?
Edit:
After I added the new dependency in pom
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
I solve the above problem but this time hit me the new one it says:
No session repository could be auto-configured, check your configuration (session store type is 'redis'
My redis configuration on application.yml is above. And I am using redis on docker. My docker yml is:
redis:
image: redis
ports:
- "6379:6379"
答案1
得分: 6
我最近遇到了这个错误。我正在使用Spring Boot 2.4.0版本。我已经添加了Spring Session的依赖,但是忘记添加Jedis的依赖。
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
当我首次部署时,出现了以下消息:
无法自动配置会话存储库,请检查您的配置(会话存储类型为'redis')
在我添加了这个依赖并重新构建了我的JAR文件之后,一切正常了。
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
也许这会对其他人有所帮助。
英文:
I got this error recently. I was using Spring Boot 2.4.0. I had added the dependency for Spring Session, but forgot to add one for Jedis.
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
When I first deployed, with that it gave me the message:
No session repository could be auto-configured, check your configuration (session store type is 'redis')
After I added this dependency and rebuilt my JAR, everything worked.
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
Perhaps that will help someone else.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论