I have read the Spring Boot documentation and I got knowledge about Spring Session from this document.
But I see that HttpSession class works without adding any dependencies in my code.
JDBC
Redis
Hazelcast
MongoDB
So...
I'm guessing that Spring Boot provides Session Storage by default. Does anyone know about this? I looked at spring docs but couldn't find it.
How to you run your app? Do you use Tomcat or Jetty embedded server or deploy it in those servers? They all have their own session storage implementation. Tomcat uses file-bases session storage by default.
The session storage that you mentioned by default is provided by the Servlet container.It is just an internal java.util.Map.
Spring Session is a Spring sub-project. It is optional and its purpose is to allow you swap the session stroage mechanism provided by the container with the one provided by Spring Session which can be RDBMS, Redis ,Hazelcast Cluster or MongoDB .HttpSession is then stored in the container agnostic way such that you can have session persistence /session clustering more easier. You no longer need to consult the Servlet container documentation for how to configure a cluster etc.
If you want to use Spring session, you still have to include the dependencies from the spring session project.
Related
I am facing issues while creating a Multitenant application using spring boot and Redis. I have used the same solution which is mentioned in How to implement multitenancy for Redis in spring boot. But it didn't work. Is there a different way to implement Redis multitenancy with Spring boot.
I found the solution by adding a check if the data source not available in the cache then pull from the required source and create a connection. Also changed calling afterPropertiesSet() explicitly which is mentioned in How to implement multitenancy for redis in spring boot
Is it safe to store references to an HttpSession in an HashMap?
I have a Spring application deployed in Wildfly 10.1 with in the web.xml. The HttpSessions that are created are org.wildfly.clustering.web.undertow.session.DistributableSession which I believe is indirectly stored in a distributed Infinispan cache.
Right now all I am looking to do is update the last access time after Websocket pings. Ideally I would be using Spring Sessions, which has this functionality built in, but I don't see an easy way to integrate Spring Session 2.0.3 with the built in Infinispan 8.2.4.
In one of our product we are using Spring ver. 4 framework. This product is hosted on Azure or AWS based on customer's preference. We would like to enable memcache for better performance.
Our desired configuration will be :
applicationContext.xml which will include cacheConfig.xml
This cacheConfig.xml (which may include a property file), should specify :
Is cache enabled OR disabled
Cache Provider.
I checked about spring simple memcache lib., which supports AWS Memcache.
We did couple of POC but all of them suggests change in code or use maven profile.
But not much luck.
I hope we are moving in right direction. Any comment/answer is most welcomed!
Thanks in advance.
You could disable caching with configuration property spring.cache.type=none. You could check out Memcached Spring Boot library which provides implementation for the Spring Cache Abstraction.
We have a Java Spring application running on dedicated bluemix with Tomcat and cloudfoundry. We want to increase the number of running instances, thus we need to replicate our session variables to each instance.
From our perspective the natural path would be using Redis and Spring Sessions.
However, there is big red tag telling us that bluemix Redis support is experimental and should not be used in production environments.
If we can't use Redis in production environments, what is the alternative to session cluster aware in dedicated bluemix?
The two services that are available in Public that you could use are "Session Cache" and "Compose for Redis".
Session Cache: Improve application resiliency by storing session state information across many HTTP requests. Enable persistent HTTP sessions for your application and seamless session recovery in event of an application failure.
You can use Compose Enterprise in Bluemix Dedicated which contains production ready Redis: https://enterprise.compose.com/
I've been doing Java standard edition development for awhile, and the frameworks and solutions have been fairly obvious to me (Swing for GUI, etc). I've recently begun the task of building a server for my own needs and to host a web page (things the server will be doing in addition to hosting a web page would include personal SVN hosting and integrating more web functionality into existing and future applications). For coding for only a single computer (that is, distributed computing, etc. is not really a concern)- I'm not entirely certain between Spring, Hibernate and EJB and am not very knowledgeable as to the capabilities of each. Information would be appreciated. I know Spring is an alternative to EJB, and Hibernate is an object-relational mapping library, so does EJB combine the two?
EJB3 in summary consists of 3 bean types; Message Driven Beans, Stateless/Stateful Session Beans and Entity Beans or JPA (Java Persistance Architecture). Hibernate can be used as a JPA provider, but it doesn't have to be used that way.
Spring has functionality that is roughly similar to Message Driven Beans and Stateless/Stateful session beans but it does not have an equivalent to JPA. Instead it allows you to utilize JPA or hibernate directly but if you do combine Spring with JPA you'll need an EJB container.
Another difference is that EJB is provided by 'containers' whereas spring is a framework that can be deployed into a java se application or a java servlet container web application like jetty or tomcat. Its an important distinction to make. Tomcat is not an EJB container, only a servlet container, hence if you were to only use basic tomcat, you couldn't use EJBs but you could use spring by including the required spring jar files in your web application (WEB-INF/lib). In that case you wouldn't use JPA either but you could use hibernate.
Some java servers that ARE EJB containers include weblogic, websphere, jboss, geronimo, and glassfish. Tomcat can become an EJB container if you combine it with OpenEJB.
In an application i'm developing at the moment, I'm using tomcat + openejb so I have an EJB container so I can use JPA with OpenJPA as the persistance provider. I'm using Spring MVC to do the web application development and will most likely use spring security as well down the track. I probably will also use Stateless Session EJBs as well to encapsulate business functionality but i could just as easily use Spring service/dao beans instead of statless session ejbs as well.
Its pretty confusing sometimes to work out what parts of which framework or container you should use and really comes down to either preference or using functionality in one that doesn't exist in the other or ease of use. Another consideration is memory utilization. Some of the ejb containers consume large amounts of memory just starting up with no applications running. This is one reason I ended up using tomcat + openejb. Hope this helps.