没有会话存储库可以自动配置(会话存储类型为’redis’)

huangapple go评论70阅读模式
英文:

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.

&lt;properties&gt;
	&lt;java.version&gt;14&lt;/java.version&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-data-redis&lt;/artifactId&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
		&lt;scope&gt;test&lt;/scope&gt;
	&lt;/dependency&gt;
&lt;/dependencies&gt;


&lt;build&gt;
	&lt;plugins&gt;
		&lt;plugin&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
		&lt;/plugin&gt;
	&lt;/plugins&gt;
&lt;/build&gt;

</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

	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
		&lt;artifactId&gt;spring-session&lt;/artifactId&gt;
		&lt;version&gt;1.3.5.RELEASE&lt;/version&gt;
	&lt;/dependency&gt;

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:
         - &quot;6379:6379&quot;

答案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.

        &lt;dependency&gt;
			&lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
			&lt;artifactId&gt;spring-session-data-redis&lt;/artifactId&gt;
		&lt;/dependency&gt;

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 &#39;redis&#39;)

After I added this dependency and rebuilt my JAR, everything worked.

        &lt;dependency&gt;
			&lt;groupId&gt;redis.clients&lt;/groupId&gt;
			&lt;artifactId&gt;jedis&lt;/artifactId&gt;
		&lt;/dependency&gt;

Perhaps that will help someone else.

huangapple
  • 本文由 发表于 2020年8月16日 19:49:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63436508.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定