You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jetty 12迁移后配置jetty-ssl.xml遇ServerConnector构造函数匹配错误

解决方案

1. 更新DTD声明

将XML开头的DTD替换为Jetty 12对应的版本,避免解析兼容性问题:

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_12_0.dtd">

2. 修正ServerConnector构造函数调用

Jetty 12的XmlConfiguration不再支持通过name属性指定构造函数参数,需严格按参数顺序传递,同时调整ConnectionFactory的配置逻辑:

修改后的完整jetty-ssl.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_12_0.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">

  <!-- 关联默认HttpConfiguration(若不存在则新建),确保HTTPS继承HTTP核心配置 -->
  <New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
    <Arg><Ref refid="httpConfig"/></Arg>
    <Set name="secureScheme">https</Set>
    <Set name="securePort"><Property name="jetty.ssl.port" default="8443"/></Set>
  </New>

  <!-- 配置SSL上下文工厂 -->
  <New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
    <Set name="keyStorePath"><Property name="jetty.sslContext.keyStorePath" default="/etc/keystore.p12"/></Set>
    <Set name="keyStorePassword"><Property name="jetty.sslContext.keyStorePassword" default="storepwd"/></Set>
    <Set name="keyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword"/></Set>
  </New>

  <!-- 创建SSL Connector -->
  <Call name="addConnector">
    <Arg>
      <New id="sslSdaConnector" class="org.eclipse.jetty.server.ServerConnector">
        <!-- 第一个参数:Server实例 -->
        <Arg><Ref refid="Server"/></Arg>
        <!-- 第二个参数:ConnectionFactory数组 -->
        <Arg>
          <Array type="org.eclipse.jetty.server.ConnectionFactory">
            <Item>
              <New class="org.eclipse.jetty.server.SslConnectionFactory">
                <Arg><Ref refid="sslContextFactory"/></Arg>
                <Arg>http/1.1</Arg>
              </New>
            </Item>
            <Item>
              <New class="org.eclipse.jetty.server.HttpConnectionFactory">
                <Arg><Ref refid="sslHttpConfig"/></Arg>
              </New>
            </Item>
          </Array>
        </Arg>
        <!-- 设置Connector基础属性 -->
        <Set name="port"><Property name="jetty.ssl.port" default="8443"/></Set>
        <Set name="idleTimeout"><Property name="jetty.ssl.idleTimeout" default="30000"/></Set>
        <Set name="host"><Property name="jetty.ssl.host" default="localhost"/></Set>
      </New>
    </Arg>
  </Call>

</Configure>

3. 同步ssl.ini配置

确保ssl.ini中的属性与XML配置对应,示例配置:

jetty.ssl.port=8443
jetty.ssl.host=localhost
jetty.ssl.idleTimeout=30000

jetty.sslContext.keyStorePath=/etc/keystore.p12
jetty.sslContext.keyStorePassword=storepwd
jetty.sslContext.keyManagerPassword=keymanagerpwd

核心变更说明

  • DTD版本匹配:必须使用Jetty 12专属DTD,否则XML解析会触发兼容性错误。
  • 构造参数传递方式:Jetty 12移除了通过name属性指定构造参数的逻辑,需严格按构造函数参数顺序传递。
  • HttpConfiguration关联:SSL的HttpConfiguration需继承默认配置,确保编码、错误页面等HTTP特性在HTTPS场景下正常生效。

内容的提问来源于stack exchange,提问作者Adam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 20:14:52