标签: spring-session

bean的会话范围如何在Spring MVC应用程序中运行?

我是Spring MVC的新手,我对bean 的会话范围有疑问.

进入一个项目我有一个Cartbean,这个:

@Component
@Scope(value=WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Cart {


    private Map<Product, Integer> contents = new HashMap<>();

    public Map<Product, Integer> getContents() {
        return contents;
    }

    public Set<Product> getProducts() {
        return contents.keySet();
    }

    public void addProduct(Product product, int count) {

        if (contents.containsKey(product)) {
            contents.put(product, contents.get(product) + count);
        } 
        else {
            contents.put(product, count);
        }
    }


    public void removeProduct(Product product) {
        contents.remove(product);
    }

    public void clearCart() {
        contents.clear();
    }

    @Override
    public String toString() {
        return contents.toString(); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-session

2
推荐指数
1
解决办法
9280
查看次数

如何更改 spring 会话(redis)cookie 名称?

我们在同一个域后面有两个项目(前面有 zuul proxy ),两个项目都使用 spring 会话项目,会话保存在 redis 中。

这两个会话应该是不同的,但似乎它们正在覆盖名为“SESSION”的 cookie 中的彼此 ID。如何更改该名称?有没有什么简单的方法可以通过配置来做到这一点?

spring redis spring-session

2
推荐指数
1
解决办法
1万
查看次数

Spring Boot和Spring Session,在SessionAutoConfigure.java中禁用自动配置

我们有一个不使用Spring会话的用例,即@EnableRedisHttpSession即使Spring Session和Spring boot在类路径中也没有注释。我们曾经通过拥有一个自定义属性spring.session.enabled并在具有注释@ConditionalOnProperty的类上使用来做到这一点@EnableRedisHttpSession。这在Spring Boot 1.2.7中有效。但是在Spring Boot 1.3.0中,SessionAutoConfiguration该类具有@EnableRedisHttpSession注释。

有没有办法禁止使用该类?

spring-boot spring-session

2
推荐指数
1
解决办法
4024
查看次数

会话范围 bean 可以与 Spring Session 和 GemFire 一起使用吗?

“会话”范围 bean 可以与Spring Session和 Pivotal GemFire 一起使用吗?

当将Spring Session用于“会话”范围 bean 时,SpringHttpSession为此 bean创建一个额外的。这是一个存在的问题吗?

解决这个问题的方法是什么?

spring-data-gemfire spring-session

2
推荐指数
1
解决办法
1373
查看次数

如何创建 FindByIndexNameSessionRepository 的 bean

我正在尝试创建 FindByIndexNameSessionRepository 的 Bean。我需要让所有用户会话都使用它,但即使我已经定义了它,我也会收到 bean 错误。我正在使用 Spring Boot Starter 1.5.7

错误:字段 sessionRepository 需要一个无法找到的“org.springframework.session.FindByIndexNameSessionRepository”类型的 bean。

考虑在您的配置中定义一个 'org.springframework.session.FindByIndexNameSessionRepository' 类型的 bean。

我正在尝试创建 bean 并在我的配置中使用它,如下所示:

import com.x.security.SpringSessionBackedSessionRegistry;
@Bean
SpringSessionBackedSessionRegistry sessionRegistry() {
    return new SpringSessionBackedSessionRegistry<ExpiringSession>(
            this.sessionRepository);
}
@Autowired
private FindByIndexNameSessionRepository<ExpiringSession> sessionRepository;
Run Code Online (Sandbox Code Playgroud)

我的配置如下

http<...>
   .maximumSessions(2)
   .sessionRegistry(sessionRegistry())
    .maxSessionsPreventsLogin(false)
    .<other settings>           
Run Code Online (Sandbox Code Playgroud)

我的 SpringSessionBackedSessionRegistry 类如下:

public class SpringSessionBackedSessionRegistry<S extends ExpiringSession>
    implements SessionRegistry {
  private final FindByIndexNameSessionRepository<S> sessionRepository;


public SpringSessionBackedSessionRegistry(
        FindByIndexNameSessionRepository<S> sessionRepository) {
    Assert.notNull(sessionRepository, "sessionRepository cannot be null");
    this.sessionRepository = sessionRepository;
     }
     @Override
public List<Object> getAllPrincipals() {
    throw new …
Run Code Online (Sandbox Code Playgroud)

java redis spring-boot spring-session

2
推荐指数
1
解决办法
3793
查看次数

如何配置 Spring 会话以在 xml 中使用 Redis?

在我们的项目中,我们使用 xml 配置。我的任务是在 Redis 中存储会话。我在不同的网站上寻找解决方案,但找不到合适的解决方案。您能否给我解决问题的相关方法或说我做错了什么?这是我为 redis 添加的依赖项:

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session</artifactId>
            <version>1.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-data-redis</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>io.lettuce</groupId>
            <artifactId>lettuce-core</artifactId>
            <version>5.1.1.RELEASE</version>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

我在 dispatcher-servlet.xml 中添加了 bean:

<bean
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/>

<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory" p:host-name="localhost"
          p:port="6379"/>
Run Code Online (Sandbox Code Playgroud)

我在 web.xml 中的更改:

<servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

这些都是我的配置。任何帮助将不胜感激

java spring spring-mvc redis spring-session

2
推荐指数
1
解决办法
1721
查看次数

你有多个HttpSessionStrategy吗?

我想有一个基于HttpSessionStrategy下面列出的标题,但Spring Social似乎想要在会话中存储社交令牌.当它被重定向回应用程序时,没有x-auth-header指定,因此创建了一个新会话并且令牌丢失.

可我们仍然有HeaderSessionStrategyCookieSessionStrategy作为备用?

处理这个问题的最佳方法是什么?

@Bean
public HttpSessionStrategy httpSessionStrategy() {
  return new HeaderHttpSessionStrategy(); 
}
Run Code Online (Sandbox Code Playgroud)

spring-social spring-social-twitter spring-session

1
推荐指数
1
解决办法
852
查看次数

Spring Session的功能是什么?

一个简单的问题,Spring会话的用途是什么,我可以使用spring security进行会话登录?春季会议提供什么功能?

spring spring-security spring-session

1
推荐指数
1
解决办法
1339
查看次数

考虑在配置中定义类型为'org.springframework.data.redis.connection.RedisConnectionFactory'的bean

我尝试使用spring session并从git https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/spring-session下载此项目

我收到此错误应用程序未能启动


描述:

org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration中方法sessionRedisTemplate的参数0需要一个无法找到的类型为'org.springframework.data.redis.connection.RedisConnectionFactory'的bean.

行动:

考虑在配置中定义类型为'org.springframework.data.redis.connection.RedisConnectionFactory'的bean.

spring-security spring-data-redis spring-session

1
推荐指数
1
解决办法
3163
查看次数

spring security 如何维护请求之间的认证信息?

spring security 如何在请求之间维护身份验证信息?

它使用任何类似于 jSessionId 的东西还是使用完全不同的机制。

此外,我看到AbstractSecurityInterceptor(我的意思是,它的任何实现)负责拦截传入的请求并验证请求是否已被授权使用Authentication.isAuthenticated(),然后根据条件验证请求或将身份验证请求发送到 AuthenticationManager执行。那么,换句话说,AbstractSecurityInterceptor 如何区分第一个请求和后续请求。

spring spring-security jsessionid spring-boot spring-session

1
推荐指数
1
解决办法
897
查看次数