Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在docker映像中禁用SpringBoot应用程序中的Keep alive_Java_Spring Boot_Docker_Jhipster_Keep Alive - Fatal编程技术网

Java 如何在docker映像中禁用SpringBoot应用程序中的Keep alive

Java 如何在docker映像中禁用SpringBoot应用程序中的Keep alive,java,spring-boot,docker,jhipster,keep-alive,Java,Spring Boot,Docker,Jhipster,Keep Alive,我们有一个具有以下技术的Web应用程序:Java、SpringBoot、Docker、Microservices和Jhipster。 前端容器的端口号为80 我正在尝试禁用前端微服务的保持活动选项,因为SSO身份验证服务器要求将此参数设置为false 我尝试用maven创建前端容器:mvn-Pqpm,no liquibase-Dhttp.keepAlive=false clean verify jib:dockerBuild 我还尝试在前容器的pom.xml中禁用: <http.keepA

我们有一个具有以下技术的Web应用程序:Java、SpringBoot、Docker、Microservices和Jhipster。 前端容器的端口号为80

我正在尝试禁用前端微服务的保持活动选项,因为SSO身份验证服务器要求将此参数设置为false

我尝试用maven创建前端容器:
mvn-Pqpm,no liquibase-Dhttp.keepAlive=false clean verify jib:dockerBuild

我还尝试在前容器的pom.xml中禁用:

<http.keepAlive>false</http.keepAlive>
<https.keepAlive>false</https.keepAlive>
我的Springboot配置:

<!-- Dependency versions -->
<jhipster-dependencies.version>3.0.1</jhipster-dependencies.version>
<!-- The spring-boot version should match the one managed by
https://mvnrepository.com/artifact/io.github.jhipster/jhipster-dependencies/${jhipster-dependencies.version} -->
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>

3.0.1
2.1.4.1发布

你能帮我禁用它吗?

我终于找到了解决方案。我们这样做的方式是实现一个过滤器,并将该过滤器添加到SecurityConfig.config方法中

    KeepAliveFilter.java

    public class KeepAliveFilter implements Filter {
        public void init(final FilterConfig filterConfig) { }

        public void destroy() { }

        public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
            final HttpServletResponse httpResponse = (HttpServletResponse) response;
            httpResponse.setHeader("Connection", "close");
            chain.doFilter(request, response);
        }
    }

    SecurityConfiguration.java

    private final KeepAliveFilter keepAliveFilter;

    public SecurityConfiguration(final KeepAliveFilter keepAliveFilter, ...) 
    {
        this.keepAliveFilter = keepAliveFilter;
    ...
    // other property
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
            .and()
            .addFilterBefore(corsFilter, CsrfFilter.class)
            .addFilterBefore(keepAliveFilter, CsrfFilter.class)
            ;
    }

您正在使用哪个http客户端发送请求?您是否尝试在application.yml中执行此操作?检查中的可用属性,因为Jhipster默认使用Undertow,我会尝试
服务器。Undertow。始终设置keep alive
。如果您在Undertow的文档中发现Undertow设置未作为应用程序属性公开,您仍然可以通过代码进行设置。请参见Hi@GaëlMarziou,您编写的参数未知。我使用的是旧版本的Spring boot吗?我在帖子中添加了我的配置。是的,没有提到它,所以你可以将SpringBoot升级到2.2.x,这并不困难。否则,您可以通过使用UndertowBuilderCustomizer的代码将ALWAYS\u set\u KEEP\u ALIVE设置为false。这不起作用。我想它是由jhipster配置键管理的,但我没有找到它。我不知道在docker映像中将应用程序作为jar文件托管时,如何禁用此http配置。
    KeepAliveFilter.java

    public class KeepAliveFilter implements Filter {
        public void init(final FilterConfig filterConfig) { }

        public void destroy() { }

        public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
            final HttpServletResponse httpResponse = (HttpServletResponse) response;
            httpResponse.setHeader("Connection", "close");
            chain.doFilter(request, response);
        }
    }

    SecurityConfiguration.java

    private final KeepAliveFilter keepAliveFilter;

    public SecurityConfiguration(final KeepAliveFilter keepAliveFilter, ...) 
    {
        this.keepAliveFilter = keepAliveFilter;
    ...
    // other property
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
            .and()
            .addFilterBefore(corsFilter, CsrfFilter.class)
            .addFilterBefore(keepAliveFilter, CsrfFilter.class)
            ;
    }