In an attempt to externalize tomcat session for my existing application I am trying the Spring Session Redis solution. After following the steps to include necessary dependencies in pom.xml like so :
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
adding the springSessionRepositoryFilter in web.xml like this :
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
and adding the following in Spring XML configuration
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/>
<context:property-placeholder location="classpath:application.properties"/>
<bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:port="${spring.redis.port}"/>
and building and deploying on to tomcat, this is the error I am getting :
org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: com.sun.jersey.client.apache.ApacheHttpClient
Any suggestion to or help is greatly appreciated. Thanks !! Also attached are my pom.xml entries : pom.xml entries
From your exception, com.sun.jersey.client.apache.ApacheHttpClient is not serializable because it did not implemented java.io.Serializable.
You need to serialize ApacheHttpClient in some other way, because it is a 3rd party library.
You can use org.codehaus.jackson.map.ObjectMapper
from the Jackson library to achieve this.
Please refer this example.
You could also try SerializableEntity class shipped with HttpClient.
httpost.setEntity(new SerializableEntity(mySerializableObj, false));
Below are the general approaches to make a class serializable.