首页 文章

Jetty ServletContainerInitialization(SCI)不会调用Web片段中提供的初始化程序

提问于
浏览
0

这是场景,

  • webapp包含 web.xml

  • 其中一个jar包含ServletContainerInitializer

META-INF/services/javax.servlet.ServletContainterInitializer

我们通过使用配置了服务器对象的XMLConfiguration以编程方式启动jetty .

XmlConfiguration configuration = new XmlConfiguration(in);

    if (type.isInstance(server))
    {
        configuration.configure(server);

        return;
    }

    boolean success = false;

    for (Handler handler : ((Server) server).getHandlers())
    {
        if (type.isInstance(handler))
        {
            configuration.configure(handler);

            success = true;
        }
    }

这是使用的XML文件 .

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Configure class="org.eclipse.jetty.server.Server" id="Server">
<Set name="ThreadPool">
    <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
        <Set name="minThreads">2</Set>
        <Set name="maxThreads">10</Set>
        <Set name="detailedDump">false</Set>
    </New>
</Set>
<Call name="addConnector">
    <Arg>
        <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
            <Set name="port">8080</Set>
            <Set name="maxIdleTime">30000</Set>
            <Set name="Acceptors">2</Set>
            <Set name="statsOn">false</Set>
        </New>
    </Arg>
</Call>
<Set name="handler">
    <New class="org.eclipse.jetty.webapp.WebAppContext">
        <Arg type="String">src/main/webapp</Arg>
        <Arg type="String">/</Arg>
        <Set name="extraClasspath">S:/git/projects/p1/target/classes;           
        S:/maven.repo/org/apache/ahc/1.1.2/ahc-1.1.2.jar;
        S:/maven.repo/com/sun/xml/bind/jaxb-xjc/2.2.3.20110115/jaxb-xjc-2.2.3.20110115.jar;
        S:/maven.repo/com/springsource/org/hsqldb/1.8.0.10/hsqldb-1.8.0.10.jar;
        S:/maven.repo/com/springsource/org/jdom/1.0.0/jdom-1.0.0.jar;
        S:/maven.repo/org/apache/mina/1.1.9/mina-1.1.9.jar;
        S:/maven.repo/com/springsource/com/mysql/jdbc/5.1.6/jdbc-5.1.6.jar;
        </Set>
    </New>
</Set>
<Set name="stopAtShutdown">true</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">true</Set>
<Set name="gracefulShutdown">1000</Set>
<Set name="dumpAfterStart">false</Set>
<Set name="dumpBeforeStop">false</Set>
</Configure>

从CLI调用时,jetty DeploymentManager扫描类路径并调用jar文件中提供的ServletContainerInitializer . 在XML配置文件中提供的等价物是什么?

当代码作为战争部署到jetty安装中时,一切都按预期工作 . 所以,这证实了一切都是正确的 .

1 回答

  • 2

    Nambi,

    以下是jetty文档页面的链接,该页面讨论了在嵌入模式下使用注释:http://www.eclipse.org/jetty/documentation/current/using-annotations-embedded.html

    你只需要在xml中做相当于java代码的东西 - 总是在jetty中非常简单 . 如果您需要提示,请查看您的发行版并查看etc / jetty-annotations.xml文件正在执行的操作 .

    另外,如果你在extraClasspath上的jar中有注释,那么你需要使用9.0.6-SNAPSHOT的jetty,因为我刚刚实现了这个功能:)

    一月

相关问题