使用多个服务器 (J2EE) 存储上下文属性的位置

Where store context attributes using several servers (J2EE)

我目前正在使用 Java EE 和 Tomcat 服务器开发 Wepapp。我正在使用如下上下文属性:

ServletContext context = getServletConfig().getServletContext();
String defaultUser = (String) context.getAttribute("default_user");

但最近我读到,当你在多个服务器上部署你的 webapp 时,不建议使用上下文属性。

这是真的吗? 我该如何解决?也许我将来会使用多个服务器(AWS 或其他东西)。

谢谢!

PS:我真的只将上下文属性用于只读目的,只需阅读配置参数。

例如看到 Servlet Context in Clustered Environment,它解释了问题:

In cases where the container is distributed over many virtual machines, a Web application will have an instance of the ServletContext for each JVM.

Context attributes are local to the JVM in which they were created. This prevents ServletContext attributes from being a shared memory store in a distributed container. When information needs to be shared between servlets running in a distributed environment, the information should be placed into a session , stored in a database, or set in an Enterprise JavaBeans component. Session attributes must be serializable if they are to be processed across multiple JVMs, which is a requirement for clustering. It is possible to make some fields of a session attribute non-clustered by declaring those fields as transient.