【问题标题】:java.lang.reflect.InvocationTargetException in jetty-web.xml when setting WebAppContext.configurationClasses设置 WebAppContext.configurationClasses 时,jetty-web.xml 中的 java.lang.reflect.InvocationTargetException
【发布时间】:2013-12-10 03:12:18
【问题描述】:

我正在尝试将org.eclipse.jetty.annotations.AnnotationConfiguration 添加到org.eclipse.jetty.webapp.WebAppContextconfigurationClasses 属性中,但是(使用sbt containe:start 调用Jetty 时),得到:

[warn] Config error at <Set name="configurationClasses">
[warn]         <Array type="java.lang.String"><Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item><Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item><Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item><Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item><Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item><Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item><Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item><Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item></Array>
[warn]     </Set>java.lang.reflect.InvocationTargetException in file:/Users/erik.allik/code/scala/webtest/src/main/webapp/WEB-INF/jetty-web.xml
[warn] Failed startup of context o.e.j.w.WebAppContext@33acb4a1{/,[file:/Users/erik.allik/code/scala/webtest/src/main/webapp/],STARTING}

我尝试将 &lt;Set ...&gt; 更改为 &lt;Call name="setConfigurationClasses"&gt;(同时使用 String[]List&lt;String&gt; 变体)但无济于事 - 每次仍然得到相同的反射异常。

我的jetty-web.xml如下:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="configurationClasses">
        <Array type="java.lang.String">
            <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
            <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
            <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
            <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
            <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
            <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
            <Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
            <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
        </Array>
    </Set>
</Configure>

回答:https://github.com/JamesEarlDouglas/xsbt-web-plugin/blob/master/src/jetty-9/scala/Jetty9Runner.scala 决定,xsbt-web-plugin 将 WebAppContext 的配置属性设置为硬编码值,因此无论 XML 配置中的内容是什么,它都可能被忽略(或者显然会导致错误)。

【问题讨论】:

    标签: jetty sbt xsbt-web-plugin jetty-9


    【解决方案1】:

    配置类用于配置WebAppContext 本身。

    jetty-web.xml 或 Jetty IoC XML Context Deployable 中添加配置在生命周期中为时已晚。

    如果您查看etc/jetty-annotations.xml,您会看到...

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
    
    <Configure id="Server" class="org.eclipse.jetty.server.Server">
      <!-- =========================================================== -->
      <!-- Add annotation Configuring classes to all webapps for this Server -->
      <!-- =========================================================== -->
      <Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault">
        <Arg><Ref refid="Server" /></Arg>
        <Call name="addBefore">
          <Arg name="beforeClass">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Arg>
          <Arg>
            <Array type="String">
              <Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
            </Array>
          </Arg>
        </Call>
      </Call>
    </Configure>
    

    etc/jetty-plus.xml 你会看到...

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
    
    <!-- =============================================================== -->
    <!-- Configure extended support for webapps                          -->
    <!-- =============================================================== -->
    <Configure id="Server" class="org.eclipse.jetty.server.Server">
    
      <!-- =========================================================== -->
      <!-- Add plus Configuring classes to all webapps for this Server -->
      <!-- =========================================================== -->
      <Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault">
        <Arg><Ref refid="Server" /></Arg>
        <Call name="addAfter">
          <Arg name="afterClass">org.eclipse.jetty.webapp.FragmentConfiguration</Arg>
          <Arg>
            <Array type="String">
              <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
              <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
            </Array>
          </Arg>
        </Call>
      </Call>
    </Configure>
    

    如果您注意到,您会看到这些是在服务器级别配置的,并且基于现有的默认值(以满足配置的排序要求)。

    【讨论】:

    • wiki.eclipse.org/Jetty/Feature/Annotationswiki.eclipse.org/Jetty/Feature/Annotations“将配置应用于单个 webapp” 部分怎么样?
    • 该文档适用于 Jetty 7(又名 Servlet 2.5) - Jetty 9 文档(又名 Servlet 3.1)位于 eclipse.org/jetty/documentation/current/annotations.html - 对 servlet / 过滤器 / websockets / 等的注释扫描...(又名端点) 在 WebSocketContext 中不受支持。如果您觉得这很重要,请在 bugs.eclipse.org(在 RT/Jetty 下)提交错误。
    • WebAppContext 不支持”你的意思是说?
    • ...无论如何,当使用 xsbt-web-plugin 和嵌入式 Jetty 时,除了直接在 Java/ 中创建 Jetty 实例之外,还有什么方法可以更改配置列表Scala 代码(而不是让 xsbt-web-plugin 的 container:start 命令为我这样做)?
    • @ErikAllik (aka RaceCondition on irc) 请重新加入 irc。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 2020-08-19
    • 2018-09-11
    • 2012-08-29
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    相关资源
    最近更新 更多