有没有办法指定web.xml和web-fragment.xml中定义的ServletContextListener的执行顺序?
我的应用程序中有两个监听器: 第一个在 web-fragment.xml 中声明
<listener>
<listener-class>com.example.RunFirst</listener-class>
</listener>
第二个位于我的应用程序的 web.xml 中
<listener>
<listener-class>com.example.RunSecond</listener-class>
</listener>
此外,我的网络片段包含以下排序元素:
<ordering>
<before>
<others />
</before>
</ordering>
但是RunSecond仍然在RunFirst之前执行。知道如何更改此订单吗?
最佳答案
实际上根本不可能。
正如 Oracle 文档中所述:“始终首先处理 web.xml 描述符。”
您可以做的是使用 RunSecond 监听器创建另一个 web-fragment.xml,并使用“排序”设置片段之间的相对顺序。
希望有帮助。
关于java - web片段和web.xml中servlet监听器的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26718165/