我有我的自定义 tomcat Valve 扩展 FormAuthenticator,并且在每个 webapp 的 context.xml 中定义了相同的内容。我需要根据 webapp 名称读取 Valve 的“initInternal”中的一些属性文件。即对于每个 webapp 不同的属性文件。由于 Valve 很常见,我需要一种方法来找出加载 Valve 的上下文。有什么方法可以在 Valve 类中获取上下文。
我试图在“ServletContextListener”中设置系统属性,但在初始化 ServletContextListener 之前加载了 Valve 类。
这是我的 context.xml 的外观。
<Context className="org.apache.catalina.core.StandardContext" debug="0" allowLinking="true" docBase="auth" path="/auth" privileged="true" reloadable="false">
<Realm className="org.apache.catalina.realm.LockOutRealm" failureCount="5" lockOutTime="300" >
<Realm className="com.foo.realm.FooRealm" /></Realm>
<Valve className="com.foo.valves.FooRESTValve" />
</Context>
每个 webapp 只有 'docbase' 和 'path' 不同。