1

次のようなTomcatを埋め込むコードがあります。

public void start()
{
    final Tomcat tomcat = createTomcat();

    try
    {
        tomcat.start();
    }
    catch (Exception e)
    {
        throw new RuntimeException("Failed to start web server", e);
    }

    this.tomcat = tomcat;
}

private Tomcat createTomcat()
{
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir(FileUtils.getTempDirectory().getAbsolutePath());

    tomcat.setConnector(createConnector());

    // ... eliding the webapp, session, access log setup ...

    return tomcat;
}

private Connector createConnector()
{
    Connector connector = new Connector();
    connector.setPort(context.getWebServerPort());
    connector.setScheme("https");
    connector.setSecure(true);

    //prepareKeyStore(context.getListeningHost());

    connector.setAttribute("address", context.getListeningAddress());
    connector.setAttribute("SSLEnabled", true);

    // Bind on start() instead of init() so that the port is closed faster on shutdown
    // I still have another problem where stop() seems to return before shutdown is
    // truly complete!
    connector.setAttribute("bindOnInit", false);

    connector.setAttribute("keystoreFile", "/my/keystore");
    connector.setAttribute("keystorePass", "password");
    connector.setAttribute("clientAuth", "false");
    connector.setAttribute("sslProtocol", "TLS");
    connector.setAttribute("keyAlias", context.getListeningHost());
    connector.setAttribute("keyPass", "password");

    return connector;
}

これが実行されると、Tomcatはどのポートでもリッスンを開始しません。調べてみると、コネクタがまだ新品の状態であることがわかりました。

Tomcat自体を起動したときにTomcatが起動しないのはなぜですか?

stop()とdestroy()でも同じことが起こります。どちらもそれを呼んでいないようです。

エラーは発生しません。後で電話をかけるとtomcat.getConnector().start()、成功したように見え、サービスに連絡できるようになります。

4

1 に答える 1