在部署时覆盖WEB-INF / jetty-env.xml中设置的Jetty的JNDI配置

问题描述

我的Java Web应用程序必须满足以下要求:

  1. 该Web应用程序可在Jetty 9上运行
  2. Web应用程序通过JNDI接受一组属性(类java.util.Properties
  3. 该网络应用在jetty-env.xml中带有认的JNDI配置
  4. 目标环境中的码头可以覆盖jetty-env.xml中设置的JDNI配置

我可以满足要求1、2和3,但是我在为要求4挣扎。

在WAR中包装的web.xml中,有一个recource-ref

    <resource-ref>
        <res-ref-name>properties</res-ref-name>
        <res-type>java.util.Properties</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

我的jetty-env.xml(也与WAR打包在一起)包含一组认键值对:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
    
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
        <New id="properties" class="org.eclipse.jetty.plus.jndi.Resource">
            <Arg></Arg>
            <Arg>properties</Arg>
            <Arg>
                <New class="java.util.Properties">
                    <Put name="remoteHost">localhost</Put>
                </New>
            </Arg>
        </New>
    </Configure>

在目标环境中,我试图通过在webapps上下文XML下提供以下配置来覆盖jetty-env.xml中的认配置 $JETTY_BASE/webapps/mywebapp.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
    
    <Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextpath">/mywebapp</Set>
        <Set name="war">./webapps/mywebapp.war</Set>
        <New id="properties" class="org.eclipse.jetty.plus.jndi.Resource">
            <Arg><Ref refid="wac"/></Arg>
            <Arg>properties</Arg>
            <Arg>
                <New class="java.util.Properties">
                    <Put name="remoteHost">example.somewhere.com</Put>
                </New>
            </Arg>
        </New>
    </Configure>

当我从Jetty基本目录$JETTY_BASE内的CLI从CLI启动Jetty服务器时,

java -jar $JETTY_HOME/start.jar

removeUrl属性的值是localhost的值jetty-env.xml,而不是example.somewhere.com的值mywebapp.xml

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)