将Jdbc会话添加到spring boot

时间:2016-05-24 09:17:20

标签: spring spring-boot

当我们将JdbcSession添加到spring引导项目时,它是否将会话直接存储在数据库中(我的意思是关系数据库)。我的假设是如果有人重新启动tomcat,它应该加载存储在数据库中的所有会话。

我在pom.xml中添加了以下依赖项,但是我无法

 <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session-jdbc</artifactId>
                <version>1.2.0.RELEASE</version>
                <type>pom</type>
        </dependency>
        <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>4.2.5.RELEASE</version>
        </dependency>

我仍然没有在eclipse中获得@EnableJdbcJdbcHttpSession。我现在有任何标准示例我指的是http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession-jdbc.html#httpsession-jdbc-sample

我没有在pom.xml中包含redis会话,但是当我在eclipse中导入时,我仍然看到session.redis。

更新1: 我的依赖关系如下所示:

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <!-- <version>4.2.3.RELEASE</version> -->
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session-jdbc</artifactId>
        <version>1.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.2.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.0.3.RELEASE</version>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:2)

长期以来一直在努力寻找解决方案:

spring framework 1.3.5.RELEASE使用的spring-session的默认版本是1.0.2.RELEASE,它不包含@EnableJdbcHttpSession定义。

解决了这个问题:

将会话jar添加到pom中(确保它使用1.2.0.RELEASE版本):

    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session</artifactId>
        <version>1.2.0.RELEASE</version>
    </dependency>