Tag Archives: four hundred and four

[Solved] Springboot Error: swagger-UI/index.html Access Error 404

Springboot solves swagger UI/index HTML Access Error 404

Recently, I was working on a project to adopt swagger 3.0. After the project is started, access the swagger path: http://localhost:8880/vdmpess -web/swagger-ui/index. HTML reports 404 because webmvcconfig inherits webmvcconfigurationsupport. After inheriting this class, the relevant contents configured in the configuration file will become invalid and the static resource needs to be re specified
the swagger static resource needs to be re specified.

Swagger address in project

Solution:

Adds the address of the specified static resource

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.
                addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }
}

[Solved] Error during WebSocket handshake Unexpected response code 404

Problem Description: the websocket project was well deployed before. When it was transplanted to the domain name specified by the government cloud SLB, an error occurred:
error during websocket handshake unexpected response code 404

Solution

1. Configure nginx

In any case, configure nginx:
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;

location /xxx{
    proxy_pass http://127.0.0.1:7071/xxx;
    proxy_redirect    off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_http_version 1.1;
    proxy_set_header Connection "upgrade";
    proxy_set_header Upgrade $http_upgrade;
    
    proxy_connect_timeout 60s;
    proxy_read_timeout 7200s;
    proxy_send_timeout 600s;
    
    # 再不行的话就把下面的设置试一下
    #proxy_set_header Upgrade websocket;
    #proxy_pass_request_headers on;
    #access_log off;
    #proxy_buffering off;
    
}

2. Websocket configuration

We use springboot, and all configurations cannot be less

import com.fh.websocket.session.MySpringConfigurator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * enable WebSocket support
 */
@Configuration
public class WebSocketConfig {

	@Bean
	public ServerEndpointExporter serverEndpointExporter() {
		return new ServerEndpointExporter();
	}

	@Bean
	public MySpringConfigurator mySpringConfigurator() {
		return new MySpringConfigurator();
	}
}

3. Websocketserver needs to add a parameterless constructor

This is a pit, and it is normal to deploy to another
transplanting will not work in the past.

SSM custom 404 and 500 error reporting interface

SSM custom 404 and 500 error reporting interface

1. In web.xml Configuration 2, test 404 error

1. In web.xml Medium configuration

 <!--Replace the 400 and 500 error message screens-->
  <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/error/404.jsp</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/error/500.jsp</location>
  </error-page>

2. Test 404 error

As shown in the figure below, is the effect much more comfortable than a pile of newspapers.