Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

java - How do I configure this property with Spring Boot and an embedded Tomcat?

Do I configure properties like the connectionTimeout in the application.properties file or is the somewhere else to do it? I can't figure this out from Google.

Tomcat properties list

I found this Spring-Boot example, but it does not include a connectionTimeout property and when I set server.tomcat.connectionTimeout=60000 in my application.properties file I get an error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Spring Boot 1.4 and later

As of Spring Boot 1.4 you can use the property server.connection-timeout. See Spring Boot's common application properties.

Spring Boot 1.3 and earlier

Provide a customized EmbeddedServletContainerFactory bean:

@Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();

    factory.addConnectorCustomizers(connector -> 
            ((AbstractProtocol) connector.getProtocolHandler()).setConnectionTimeout(10000));

    // configure some more properties

    return factory;
}

If you are not using Java 8 or don't want to use Lambda Expressions, add the TomcatConnectorCustomizer like this:

    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
            ((AbstractProtocol) connector.getProtocolHandler()).setConnectionTimeout(10000);
        }
    });

The setConnectionTimeout() method expects the timeout in milliseconds (see connectionTimeout in Apache Tomcat 8 Configuration Reference).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...