有没有比 servlet 上下文更高层次的东西
Servlet 上下文是每个应用程序(或每个 .WAR)。是否有什么东西可以存储属性,以便服务器上/EAR 内的所有应用程序都可以使用?
Servlet context is per application (or per .WAR). Is there anything that attributes can be stored to, to be available to all applications on a server / within an EAR?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AFAIK,不,这就是 Servlet 规范的范围。您当然可以研究 JNDI(通常用于跨多个 Web 应用程序查找连接)等解决方案或分布式数据结构提供程序,如 淡褐色。
AFAIK, no, that's as far as the Servlet specification goes. You can of course look into solutions like JNDI (which is typically used for looking up Connections across multiple web applications) or a distributed data structure provider like Hazelcast.
EAR/WAR 通常仅限于其自身范围,但某些容器具有“共享库”的概念,它可以提供您想要的内容。一些容器使用平面类加载器,这意味着 WAR A 中的静态字段可以在 WAR B 中看到。总之,我建议 系统属性 对于大多数服务器范围的属性,除非属性不是那么静态。
对于更多动态数据,我建议的最后一个选项是创建一个包含所需值的 JAR,并将其添加到服务器的类路径中。除其他问题外,必须非常小心地确保线程安全。
EARs/WARs are usually scoped to themselves but some containers have the notion of "shared libraries" which may offer what you want. Some containers use flat classloaders which means static fields from WAR A can be seen in WAR B. All-in-all I would recommend system properties for most server wide attributes unless the properties are not so static.
For more dynamic data, the final option I would recommend would be to create a JAR with the needed values and add it to the server's class path. Great care must be taken to ensure thread safety among other issues.