能进knife4j的页面但是扫不到打了注解的接口

发布于 2022-08-15 04:48:05 字数 2735 浏览 33 评论 4

1.依赖

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>2.0.7</version>
</dependency>

 

2.knife4j配置

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("MOM接口文档")
                        .description("swagger knife4j测试")
                        .termsOfServiceUrl("http://www.baidu.com/")
                        .contact("zhizhizhi")
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("2.X版本")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}

3.oauth2.0配置资源放行:

http
        .apply(config)
        .and()
        .csrf().disable()
        .requestMatchers().antMatchers("/**")
        .and().authorizeRequests()
        .antMatchers("/oauth/token", "/error", "/exceptioncode/api",
                "/**/swagger-ui.html",
                "/swagger-ui.html",
                "/**/doc.html",
                "/doc.html",
                "/v2/api-docs", // swagger api json
                "/v2/api-docs-ext",
                "/swagger-resources/configuration/ui", // 用来获取支持的动作
                "/swagger-resources", // 用来获取api-docs的URI
                "/swagger-resources/configuration/security", // 安全选项
                "/swagger-resources/**",
                "/webjars/**").permitAll()
        .antMatchers(anonymousUrls.toArray(new String[0])).anonymous()
        .anyRequest().authenticated();

4.controller里的注解

@Slf4j
@RestController
@RequestMapping("/problemPool")
@Api(value = "改善池")
public class ProblemPoolController {
    @Autowired
    ProblemPoolService problemPoolService;

    @GetMapping("/list")
    @ApiOperation(value = "向客人问好")
    public PageResult<ProblemPoolVO> list(OmProblemPoolRequest omProblemPoolRequest, int pageIndex, int pageSize) {
        PageRequest pageRequest = PageUtil.of(pageIndex, pageSize);
        return problemPoolService.list(omProblemPoolRequest, pageRequest);
    }

5.页面上没有接口信息

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝不服输 2022-08-19 07:27:26

我是,这里Controller路径写错了

撩心不撩汉 2022-08-18 16:35:56

作者你好,请问你解决了吗

锦爱 2022-08-18 09:32:20
@Api(tags= "改善池")  这个写法吧
夜空下最亮的亮点 2022-08-18 07:30:46

你先用swagger,如果没问题,knife4j就没问题

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文