pom.xml 文件
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>4.0.0</version>
</dependency>
application.yml
server:
port: 9001
profiles:
active: prod
application-prod.yml
knife4j:
production: true
目的是开启生产环境,屏蔽所有资源接口,但是访问http://ip:port/doc.html依旧可以访问到接口,清空缓存也一样。
这个配置似乎没起到关闭的作用。
你不把knife4j自己的开关(knife4j.enable=true
)打开,他怎么生效啊
spring:
profiles.active: prod
knife4j:
production: true # 开启屏蔽文档资源
enable: true
enable:false可以正常启动,enable:true的时候报错:
ailed to instantiate [com.github.xiaoymin.knife4j.spring.filter.ProductionSecurityFilter]: Factory method 'productionSecurityFilter' threw exception; nested exception is java.lang.NullPointerException
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>4.0.0</version>
</dependency>
根据作者的建议将 knife4j 的 enable: true 打开。
application.yml
spring:
profiles.active: prod
knife4j:
production: true # 开启屏蔽文档资源
enable: true
enable:false可以正常启动,enable:true的时候报错,这个有哪位同学遇到过?
ailed to instantiate [com.github.xiaoymin.knife4j.spring.filter.ProductionSecurityFilter]: Factory method 'productionSecurityFilter' threw exception; nested exception is java.lang.NullPointerException
根据报错我跟踪了下源代码:发现以上图片信息。然后尝试knife4j.setting.custom-code=200就可以了,但我补知道为什么?因为上面图片中还有下面这个方法啊。为什么一定要加上
knife4j.setting.custom-code=200 #为什么一定要加上这句
knife4j.production=true
public ProductionSecurityFilter(boolean production) {
this.production = production;
}
另外,在作者提供的 swagger-bootstrap-ui-gateway 这个 网关 工程中:
application.properties 增加如下,但并没有屏蔽掉接口文档。如果是单独的spring boot工程是可以生效的。
#屏蔽接口文档
knife4j.enable=true
knife4j.setting.custom-code=200
knife4j.production=true
那么在spring cloud gateway网关下有什么办法屏蔽掉文档接口吗。当然如果我注释或者删除掉config包下的配置文件是可以的。但可以从application这种配置文件下通过设置配置进行吗?还是目前暂不支持。
登录 后才可以发表评论