Spring Session JdbcHttpSessionConfiguration导致JPA bean无法启动

时间:2018-07-19 12:02:20

标签: spring spring-jdbc spring-session

我正在尝试将Spring Session与PostgreSQL一起使用来存储http会话。https://docs.spring.io/spring-session/docs/2.0.4.RELEASE/reference/html5/guides/xml-jdbc.html#httpsession-jdbc-xml-sample

这是我的XML

<context:annotation-config/>
    <bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
        <property name="driverClassName" value="org.postgresql.Driver"></property>  
        <property name="url" value="jdbc:postgresql://127.0.0.1:5432/myapp"></property>  
        <property name="username" value="postgres"></property>  
        <property name="password" value=""></property>  
    </bean> 
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <constructor-arg ref="dataSource"/> 

我的应用程序已经将Spring JPA用于其他数据库操作。但是问题是在我添加

之后
<context:annotation-config/>
    <bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration"/>

我的JPA bean没有在启动时加载,因此应用程序无法启动。
我尝试了以下步骤。

  1. 创建了两个数据源bean。一种已经用于JPA,另一种已经在ID为'dataSource'的XML中显示。 JPA one也具有相同的bean属性,但具有不同的id。
  2. 当我阅读JdbcHttpSessionConfiguration时,将XML中的一个删除,并将JPA也重命名为“ dataSource”,以查找bean“ dataSource”,并假设JPA和会话JDBC将使用相同的

但是两种情况都会导致相同的错误。 我在catalina.out中没有任何错误。因此,将try catch放入我的应用程序中,尝试获取JPA bean。我收到以下错误。
 找不到bean的类[org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration] 名称为“ org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration#0” 在类路径资源[applicationContext_Web.xml]中定义;嵌套的异常是java.lang.ClassNotFoundException: org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration

在pom中添加了依赖性

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

1 个答案:

答案 0 :(得分:0)

我可以解决。某种程度上,maven仍在选择spring-session-core jar而不是spring-session-jdbc。我刚刚删除pom,然后再次进行了maven更新。不确定当时的情况如何。