2013-11-25 29 views
0

我嘗試添加org.eclipse.jetty.annotations.AnnotationConfigurationorg.eclipse.jetty.webapp.WebAppContextconfigurationClasses財產,但(與sbt containe:start調用碼頭時),得到:java.lang.reflect.InvocationTargetException在碼頭-web.xml中設置WebAppContext.configurationClasses

[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 [email protected]{/,[file:/Users/erik.allik/code/scala/webtest/src/main/webapp/],STARTING} 

我試過將<Set ...>更改爲<Call name="setConfigurationClasses">(同時使用String[]以及List<String>變體)無效 - 每次都會得到相同的反射異常。

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的插件設置的WebAppContext配置屬性設置爲一個硬編碼值,所以無論在XML CONFIGS什麼,它可能只是被忽略(或者顯然會導致錯誤)。

回答

1

配置類存在配置WebAppContext本身。

jetty-web.xml或Jetty IoC 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> 

如果你發現,你會看到,這些都是在服務器級配置,並基於現有的默認值(以滿足配置的訂購要求)。

+0

*在http://wiki.eclipse.org/Jetty/Feature/Annotations上的*「將配置應用於單個webapp」*部分如何? –

+1

該文檔適用於Jetty 7(又名Servlet 2.5) - Jetty 9文檔(也稱爲Servlet 3.1)位於http://www.eclipse.org/jetty/documentation/current/annotations.html - 註釋掃描servlet/filters/WebSocketContext中不支持websockets/etc ...(aka endpoints)。如果你覺得這很重要,請在bugs.eclipse.org(在RT/Jetty下)提交bug。 –

+0

「WebAppContext'中不支持」你打算說? –