knife4j集成shiro导致localhost/doc.html访问不到解决

Spring boot+shiro+knife4j。刚刚融合了shiro进来之后,shiro放行了doc.html 和webjars之后,但是界面还是访问不到。最后是应为少了v2之类的

一直跳转login.jsp也是shiro拦截导致的结果

解决办法:

在shiro的拦截中放开这些路径

 Map<String, String> map = new HashMap<>();
        map.put("/login","anon");
        map.put("/doc.html", "anon");
        map.put("/swagger-resources/**", "anon");
        map.put("/v2/api-docs", "anon");
        map.put("/v2/api-docs-ext", "anon");
        map.put("/webjars/**", "anon");
        map.put("/**", "authc");

如果用的knife4j-openapi3-jakarta-spring-boot-starter 版本

放开路径 /v3/api-docs/**

在使用knife4j生成Swagger文档时,如果访问http://localhost:8080/doc.html被拒绝访问,可能有以下几个原因和解决方法: 1. **Spring Boot配置问题**: 确保你的Spring Boot应用程序中已经正确配置了knife4j的相关配置。例如,在你的配置类中添加@EnableSwagger2注解。 ```java @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.controller")) .paths(PathSelectors.any()) .build(); } } ``` 2. **安全配置问题**: 如果你的应用程序中使用了Spring Security或其他安全框架,确保你已经配置了允许访问/doc.html的权限。例如,在Spring Security的配置类中添加以下配置: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/doc.html", "/swagger-ui/**", "/swagger-resources/**", "/v2/api-docs").permitAll() .anyRequest().authenticated() .and() .csrf().disable(); } } ``` 3. **端口和上下文路径问题**: 确保你的应用程序运行在正确的端口和上下文路径上。如果你更改了默认的端口或上下文路径,访问路径也需要相应更改。 4. **缓存问题**: 有时候浏览器缓存可能会导致问题,尝试清除浏览器缓存或使用隐身模式重新访问。 5. **依赖问题**: 确保你的项目中已经正确添加了knife4j的相关依赖。例如,在`pom.xml`中添加以下依赖: ```xml <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <version>最新版本</version> </dependency> ``` 通过以上步骤,你应该能够解决访问http://localhost:8080/doc.html被拒绝的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值