设置WebAppContext.configurationClasses时jetty-web.xml中的java.lang.reflect.InvocationTargetException [英] java.lang.reflect.InvocationTargetException in jetty-web.xml when setting WebAppContext.configurationClasses

查看:118
本文介绍了设置WebAppContext.configurationClasses时jetty-web.xml中的java.lang.reflect.InvocationTargetException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to add org.eclipse.jetty.annotations.AnnotationConfiguration to the configurationClasses property of org.eclipse.jetty.webapp.WebAppContext but (when invoking Jetty with sbt containe:start), getting:

[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}

我尝试将<Set ...>更改为<Call name="setConfigurationClasses">(同时包含String[]List<String>变体)无济于事-每次仍然得到相同的反射异常.

I've tried changing the <Set ...> to a <Call name="setConfigurationClasses"> (with both the String[] as well as List<String> variants) to no avail—still getting the same reflection exception every time.

我的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>

答案::由

ANSWER: deciding by https://github.com/JamesEarlDouglas/xsbt-web-plugin/blob/master/src/jetty-9/scala/Jetty9Runner.scala, xsbt-web-plugin sets the configurations property of WebAppContext to a hardcoded value, so no matter what's in the XML configs, it probably simply gets ignored (or causes an error, apparently).

推荐答案

配置类用于配置WebAppContext本身.

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

Adding the Configurations in the jetty-web.xml or the Jetty IoC XML Context Deployable is too late in the lifecycle.

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

If you look at etc/jetty-annotations.xml you'll see ...

<?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>

如果您注意到,您会发现它们是在服务器级别配置的,并且基于现有的默认值(以满足配置的订购要求).

If you notice, you'll see that these are configured at the server level, and are based on existing defaults (to satisfy ordering requirements of the Configurations).

这篇关于设置WebAppContext.configurationClasses时jetty-web.xml中的java.lang.reflect.InvocationTargetException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆