设置WebAppContext.configurationClasses时,jetty-web.xml中的java.lang.reflect.InvocationTargetException

时间:2013-11-25 11:48:01

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

我正在尝试将org.eclipse.jetty.annotations.AnnotationConfiguration添加到configurationClasses的{​​{1}}属性中,但是(当使用org.eclipse.jetty.webapp.WebAppContext调用Jetty时),获取:

sbt containe:start

我尝试将[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>如下:

jetty-web.xml

ANSWER:https://github.com/JamesEarlDouglas/xsbt-web-plugin/blob/master/src/jetty-9/scala/Jetty9Runner.scala决定,xsbt-web-plugin将<?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> 的配置属性设置为硬编码值,因此无论XML配置中有什么,它都是可能只是被忽略(或导致错误,显然)。

1 个答案:

答案 0 :(得分: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>

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