I am creating a web application with JavaEE7+Wildfly10.
I use gradle for the build.
As an independent gradle project, there are two web applications, each built as a war file.
Deploy these two war files on a single Wildfly
There is currently no session sharing between these two applications.
At a minimum, cookies JSESSIONID
have different values.
The goal is that an instance of CDI Bean with @SessionScoped
can be shared.
2 The two applications are built independently, but they refer to the same jar.There is a common @RequestScoped
class.
However, there are restrictions.
Another application is also on this Wildfly server.
I don't want to share a session with you.
Is there any good way?
java gradle java-ee
The two independent WARs cannot share objects because they have different servletContexts.
JSR-000369 Java Servlet 4.0 Specification:
7.3 Session Scope HttpSession objects must be scoped at the application (or servlet context) level.The underlying mechanism, such as the cookie used to install the session, can be the same for different contexts, but the object referenced, including the attributes in that object, by next.
ServletContextAPI doc:
There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace as/catalog and positively installed via a.war file.)
The first possible response is to consolidate these WARs into one EAR.
One EAR, or one web application, can be shared.
The way WildFly works would be shared-session-config
mentioned in Another answer.
The second possible response is to manage it yourself (if the container doesn't manage it).
JBoss EAP documentation may be helpful because it includes:
Externalize HTTP Session Data to the JBoss Data Grid:
JBoss Data Grid (JDG) will be replaced by Infinispan in WildFly.
With Wildfly 10, you may be able to do so in the second commented way on This page.
It may be difficult, but... you can also choose to integrate it into one war.
© 2024 OneMinuteCode. All rights reserved.