Reputation: 37
I am trying to use Spring Session with PostgreSQL for storing http sessions, following this guide. Here is my 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"/>
My application is already using Spring JPA for other DB operations, but there is a problem after I added:
<context:annotation-config/>
<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration"/>
My JPA beans are not loaded on startup - hence the application is not starting. I tried the following steps:
Created two data sources beans. One was already there for JPA and one as shown in the XML with id 'dataSource'. JPA one is also with same bean properties but with different id.
Removed one in XML and renamed JPA one also to 'dataSource' as I read JdbcHttpSessionConfiguration looks for bean 'dataSource' and by assuming both JPA and session JDBC will use the same one
But both the cases result in the same error. I was not getting any error in catalina.out. So put try catch in my application where it tries to get the JPA bean. I am getting the following error:
Cannot find class [org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration] for bean with name 'org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration#0' defined in class path resource [applicationContext_Web.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration
Dependency added in 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>
Upvotes: 1
Views: 1764
Reputation: 37
I could solve it . Somehow maven was still picking spring-session-core jar instead of spring-session-jdbc. I just removed pom and again did a maven update. Not sure how it took the correct one then.
Upvotes: 0