springboot uploaded file is too large, global exception caught, the client does not return value

When the recent global exception handler in the project, upload the file exceeds the configured size, the exception is caught, but the interface directly reported 500 errors, and there is no return value.

From the backstage view error logs, exception has been global exception handler to capture, and the response has been completed, why not see any return to the front of it?

Find a lot of information, always I thought it was the overall return of the reason that has not be resolved, then change direction, starting from the abnormal direction to upload files.

Finally we have the results. Blog is so is described as: springboot file upload file size exceeds the configured, multiple entry and exception handling returns, so many times in response, causing the front end can not get an error message, or not, try to know.

Custom solutions, the need to configure the connector tomcat MaxSwallowSize -1 (unlimited) is greater than or equal to the spring file upload request to play a single size recommendation or greater spring configuration is provided, in addition to providing the spring property Boot Configuration Write , you need to manually configure the connector to create a tomcat

Add startup class as follows:

    @Bean
    public ServletWebServerFactory tomcatEmbedded() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
            // connector other settings...
            // configure maxSwallowSize
            if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
                // -1 means unlimited, accept bytes
                ((AbstractHttp11Protocol<?>)
                        connector.getProtocolHandler()).setMaxSwallowSize(-1);
            }
        });
        return tomcat;
    }

 Then tested and found to solve the problem.

 

 

 

 

Reference: difference SpringBoot 2.0.0 and the new version SpringBoot1.5.2 in Tomcat configuration (pits)

Guess you like

Origin www.cnblogs.com/sueyyyy/p/11578191.html