设置WebAppContext.configurationClasses时jetty-web.xml中的java.lang.reflect.InvocationTargetException [英] java.lang.reflect.InvocationTargetException in jetty-web.xml when setting WebAppContext.configurationClasses
问题描述
我试图将org.eclipse.jetty.annotations.AnnotationConfiguration
添加到org.eclipse.jetty.webapp.WebAppContext
的configurationClasses
属性中,但是(当使用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屋!