AntiResourceLocking on Tomcat 8

自古美人都是妖i 提交于 2020-05-13 06:21:07

问题


We're running Tomcat8 on Windows and redeploying applications sometimes fails due to Windows locking jars of properties.

I found this documentation saying that you have to add the AntiResourceLocking-attribute to a Context-element: Apache Tomcat 8 Configuration Reference

All our servers are built using scripts so doing this in the server.xml should not be a problem (if it works?):

<Engine name="Catalina" defaultHost="localhost">
  <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Context antiResourceLocking="true"></Context>
  </Host>
</Engine>

When the server restarts Tomcat prints the following errors and we have no real clue as to what is wrong:

Failed to initialize component     [StandardEngine[Catalina].StandardHost[localhost].StandardContext[null]]

Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[null]]

Caused by: java.lang.NullPointerException
at org.apache.catalina.core.StandardContext.getObjectKeyPropertiesNameOnly(StandardContext.java:6233)

Has anyone done this before? Am I missing something?


回答1:


What you are missing is the difference between conf/server.xml and conf/context.xml.

When you add a <Context .../> element to conf/server.xml you are defining an individual context (web application). This is equivalent to defining a <Context .../> element in CATALINA_BASE/conf/<engine-name>/<host-name>/<context-name>.xml or in a /META-INF/context.xml file packaged as part of the web application.

The <Context .../> element in conf/context.xml defines defaults for all contexts (web applications).

The single Context element you have adding in conf/server.xml is failing because you haven't specified a path.

If you really want to enable anti-resource locking for all web applications then you need to add antiResourceLocking="true" as an attribute to the <Context .../> element in CATALINA_BASE/conf/context.xml.

As an aside, this option is only a work-around for resource leaks in your web application. You might want to consider taking the time to fix those resource leaks.




回答2:


Visit http://tomcat.apache.org/tomcat-8.0-doc/config/context.html for recommended way.

You can define context.xml in META-INF/context.xml in you WAR or you can define conf/Catalina/localhost WAR_NAME.xml

  • To configure antiResourceLocking in xml add following tag in context.xml

    <Context antiResourceLocking="true"></Context>




回答3:


For me I had a very similar problem when have 2 applications on same tomcat but on different ports, defined as 2x Service tags in Server.xml file. One of configured service couldn't start. And logs were similar to described.

Problem was in invalid docBase in <Context docBase="/appliccation2" ...> path, for tomcat installed on Windows and working local the relative path were enough, but for tomcat configuration on linux server defined path in my situation should be direct location <Context docBase="/opt/.../webapps/application2" ...>




回答4:


Please check all servlet classes accurately mapped in web.xml and also confirm their path is physically exist on the server. This is what cause to throw org.apache.catalina.LifecycleException: Failed exception.



来源:https://stackoverflow.com/questions/34153700/antiresourcelocking-on-tomcat-8

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