“<Parameter>” versus “<Environment>” entries in a Tomcat Context

限于喜欢 提交于 2021-01-29 14:13:07

问题


On The Context Container page of the Tomcat documentation, I see two sections:

  • Context Parameters
  • Environment Entries

The standard names for such elements is <context-param> and <env-entry>, while the Tomcat-specific names are <Parameter> and <Environment>.

Both Context Parameters and Environment Entries appear to have the same simple job of making same value available to the servlets running in that context. For example, setting a flag to communicate some condition.

➥ What is the difference between Context Parameters and Environment Entries?

➥ Why would I choose to use one instead of the other?


回答1:


What is the difference between Context Parameters and Environment Entries?

This is the same answer as Servlet-spec: <context-param> vs <env-entry> in web.xml??

Why would I choose to use one instead of the other?

I'm assuming that you mean "why would I choose <Context>/<Environment> versus <context-param>/<env-entry>" and not "how do I decide if I want a context parameter or an environment entry". If your question is the latter, than your question is indeed a duplicate.

The reason you might want to use <Context>/<Environment> in META-INF/context.xml versus putting their analogues into WEB-INF/web.xml comes down to separation of duties in a deployment scenario. Generally speaking, programmers are the ones who are in charge of the contents of WEB-INF/web.xml and administrators or operations staff are in charge of the contents of META-INF/context.xml.

Operators can override values specified by programmers for, say, the location of a configuration file. WEB-INF/web.xml might point to a configuration file in ~/configs/app.conf while the production deployment puts that configuration file into /etc/foo/app.conf.

It's better if operators aren't making on-the-fly changes to an application's deployment descriptor. META-INF/context.xml allows them to make those kinds of adjustments without changing that deployment descriptor.

If you are a one-person operation or if everyone is DevOps or whatever, then it almost doesn't matter. But Tomcat gives you the flexibility to implement whatever policy you want to enforce in your own environment.



来源:https://stackoverflow.com/questions/58372785/parameter-versus-environment-entries-in-a-tomcat-context

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!