【问题标题】:How to configure Jetty in spring-boot (easily?)如何在 spring-boot 中配置 Jetty(很容易?)
【发布时间】:2013-12-25 14:34:17
【问题描述】:

按照本教程,我可以使用以下依赖项启动运行 Jetty 的 spring-boot。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

但是,我该如何配置 Jetty 服务器,例如:

  1. 服务器线程(队列线程池)
  2. 服务器连接器
  3. HTTPS 配置。
  4. Jetty 中提供的所有这些配置...?

有没有简单的方法在

  1. application.yml?
  2. 配置类?

任何例子都将不胜感激。

非常感谢!!

【问题讨论】:

    标签: jetty spring-boot


    【解决方案1】:

    有一些用于 servlet 容器的通用扩展点以及将 Jetty API 调用插入其中的选项,因此我假设您想要的一切都触手可及。一般建议可以在in the docs 找到。 Jetty 还没有受到太多关注,因此声明式配置的可用选项可能与 Tomcat 不同,并且肯定它不会被太多使用。如果您想帮助改变这一点,欢迎提供帮助。

    【讨论】:

    • 非常感谢您的解释!
    • "Unable to start embedded container" after add that pom, 你能帮忙检查一下stackoverflow.com/questions/39557018/…
    • 为我工作。检查 spring boot 中的示例。
    【解决方案2】:

    可以从 http://howtodoinjava.com/spring/spring-boot/configure-jetty-server/ 以编程方式配置 Jetty(部分)

    @Bean
    public JettyEmbeddedServletContainerFactory  jettyEmbeddedServletContainerFactory() {
        JettyEmbeddedServletContainerFactory jettyContainer = 
            new JettyEmbeddedServletContainerFactory();
    
        jettyContainer.setPort(9000);
        jettyContainer.setContextPath("/home");
        return jettyContainer;
    }
    

    【讨论】:

      【解决方案3】:

      如果有人使用 Spring Boot - 您可以轻松地在 application.properties 中配置它:

      server.max-http-post-size=n
      

      其中 n 是您希望将此属性设置为的最大大小。例如我使用:

      server.max-http-post-size=5000000
      

      【讨论】:

        【解决方案4】:

        截至 2020 年,在开发新版本时,您需要执行以下操作,以配置 Jetty 端口、上下文路径和线程池属性。我在 Spring Boot 2.1.6 版上对此进行了测试,而我提到的文档是针对 2.3.3 版的

        在配置文件中创建服务器工厂 bean。

        @豆角,扁豆 公共 ConfigurableServletWebServerFactory webServerFactory() { JettyServletWebServerFactory factory = new JettyServletWebServerFactory(); factory.setPort(8080); factory.setContextPath("/my-app"); QueuedThreadPool threadPool = new QueuedThreadPool(); 线程池.setMinThreads(10); 线程池.setMaxThreads(100); 线程池.setIdleTimeout(60000); factory.setThreadPool(threadPool); 返厂; }

        以下是 Spring Docs 的链接: customizing-embedded-containers

        【讨论】:

          【解决方案5】:

          Spring Boot通过属性文件提供了如下Jetty具体配置:-

          server:
            jetty:
              connection-idle-timeout: # Time that the connection can be idle before it is closed.
              max-http-form-post-size: # Maximum size of the form content in any HTTP post request e.g. 200000B
              accesslog:
                enabled: # Enable access log e.g. true
                append: # Enable append to log e.g. true
                custom-format: # Custom log format
                file-date-format: # Date format to place in log file name
                filename: # Log file name, if not specified, logs redirect to "System.err"
                format: # Log format e.g ncsa
                ignore-paths: # Request paths that should not be logged
                retention-period: # Number of days before rotated log files are deleted e.g. 31
              threads:
                acceptors: # Number of acceptor threads to use. When the value is -1, the default, the number of acceptors is derived from the operating environment.
                selectors: # Number of selector threads to use. When the value is -1, the default, the number of selectors is derived from the operating environment.
                min: # Minimum number of threads e.g. 8 
                max: # Maximum number of threads e.g. 200
                max-queue-capacity: # Maximum capacity of the thread pool's backing queue. A default is computed based on the threading configuration.
                idle-timeout: # Maximum thread idle time in millisecond e.g. 60000ms      
          

          更多配置详情请参考Spring Boot官方documentation

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2022-01-12
            • 1970-01-01
            • 2014-01-01
            • 2016-12-21
            • 2014-07-26
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多