IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

二十八、SpringBoot访问doc.html页面404

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

默认情况下并不需要添加此配置即可访问

很多朋友在使用SpringBoot集成swagger-bootstrap-ui后,都无法访问doc.html界面,此时,你可能需要实现SpringBoot的WebMvcConfigurer接口,添加相关的ResourceHandler,代码如下:

@SpringBootApplication
public class SwaggerBootstrapUiDemoApplication  implements WebMvcConfigurer{

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html").addResourceLocations("classpath*:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath*:/META-INF/resources/webjars/");
    }
}

或者


@SpringBootApplication public class SwaggerBootstrapUiDemoApplication implements WebMvcConfigurer{ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } }

如果你是使用的老的版本SpringBoot,通过继承WebMvcConfigurationSupport来扩展SpringBoot相关的配置,则把以上配置加在相应的addResourceHandlers方法中即可

推荐使用实现WebMvcConfigurer接口的方式来进行扩展

如果以上方式还是不行,建议开启Spring的Debug日志来进行跟踪,一般访问doc.html页面会出现如下日志(成功情况下):

2019-04-19 13:39:36,896 DEBUG (AbstractHandlerMethodMapping.java:312)- Looking up handler method for path /doc.html
2019-04-19 13:39:36,902 DEBUG (AbstractHandlerMethodMapping.java:322)- Did not find handler method for [/doc.html]
2019-04-19 13:39:36,921 DEBUG (AbstractUrlHandlerMapping.java:199)- Matching patterns for request [/doc.html] are [/**]
2019-04-19 13:39:36,922 DEBUG (AbstractUrlHandlerMapping.java:233)- URI Template variables for request [/doc.html] are {}
2019-04-19 13:39:36,923 DEBUG (AbstractUrlHandlerMapping.java:146)- Mapping [/doc.html] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@da32f3]]] and 1 interceptor
2019-04-19 13:39:36,957 DEBUG (RequestContextFilter.java:104)- Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@28759ea7
2019-04-19 13:39:41,649 DEBUG (RequestContextFilter.java:114)- Bound request context to thread: org.apache.catalina.connector.RequestFacade@28759ea7

同理,在使用SpringMvc或者shiro等权限框架时,如果页面无法访问,配置doc.html属性即可

关于SpringBoot的代码示例可参考swagger-bootstrap-ui-demo

干货推荐

文章永久链接:https://tech.souyunku.com/?p=11127


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(83) 打赏



未经允许不得转载:搜云库技术团队 » 二十八、SpringBoot访问doc.html页面404

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367