Commit cca8375a97d01889e2233fd829b1498aab0d1bb9
1 parent
9040b173
【新增】`yudao.error-code.enable` 错误码的开关,默认在 `local` 环境关闭自动生成错误码
Showing
3 changed files
with
8 additions
and
0 deletions
yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/ErrorCodeProperties.java
| @@ -18,6 +18,10 @@ import java.util.List; | @@ -18,6 +18,10 @@ import java.util.List; | ||
| 18 | public class ErrorCodeProperties { | 18 | public class ErrorCodeProperties { |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | + * 是否开启 | ||
| 22 | + */ | ||
| 23 | + private Boolean enable = true; | ||
| 24 | + /** | ||
| 21 | * 错误码枚举类 | 25 | * 错误码枚举类 |
| 22 | */ | 26 | */ |
| 23 | @NotNull(message = "错误码枚举类不能为空") | 27 | @NotNull(message = "错误码枚举类不能为空") |
yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeConfiguration.java
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoader; | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoader; | ||
| 6 | import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoaderImpl; | 6 | import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoaderImpl; |
| 7 | import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; | 7 | import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; |
| 8 | import org.springframework.beans.factory.annotation.Value; | 8 | import org.springframework.beans.factory.annotation.Value; |
| 9 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| 9 | import org.springframework.boot.context.properties.EnableConfigurationProperties; | 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 10 | import org.springframework.context.annotation.Bean; | 11 | import org.springframework.context.annotation.Bean; |
| 11 | import org.springframework.context.annotation.Configuration; | 12 | import org.springframework.context.annotation.Configuration; |
| @@ -17,6 +18,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; | @@ -17,6 +18,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; | ||
| 17 | * @author 芋道源码 | 18 | * @author 芋道源码 |
| 18 | */ | 19 | */ |
| 19 | @Configuration | 20 | @Configuration |
| 21 | +@ConditionalOnProperty(prefix = "yudao.error-code", value = "enable", matchIfMissing = true) // 允许使用 yudao.error-code.enable=false 禁用访问日志 | ||
| 20 | @EnableConfigurationProperties(ErrorCodeProperties.class) | 22 | @EnableConfigurationProperties(ErrorCodeProperties.class) |
| 21 | @EnableScheduling // 开启调度任务的功能,因为 ErrorCodeRemoteLoader 通过定时刷新错误码 | 23 | @EnableScheduling // 开启调度任务的功能,因为 ErrorCodeRemoteLoader 通过定时刷新错误码 |
| 22 | public class YudaoErrorCodeConfiguration { | 24 | public class YudaoErrorCodeConfiguration { |
yudao-server/src/main/resources/application-local.yaml
| @@ -204,6 +204,8 @@ yudao: | @@ -204,6 +204,8 @@ yudao: | ||
| 204 | refund-notify-url: http://niubi.natapp1.cc/api/pay/refund/notify | 204 | refund-notify-url: http://niubi.natapp1.cc/api/pay/refund/notify |
| 205 | access-log: # 访问日志的配置项 | 205 | access-log: # 访问日志的配置项 |
| 206 | enable: false | 206 | enable: false |
| 207 | + error-code: # 错误码相关配置项 | ||
| 208 | + enable: false | ||
| 207 | demo: false # 关闭演示模式 | 209 | demo: false # 关闭演示模式 |
| 208 | 210 | ||
| 209 | justauth: | 211 | justauth: |