nobugboy / ydoc Goto Github PK
View Code? Open in Web Editor NEW充分利用springboot自有注解来对文档进行描述的一款文档生成器。 让我们抛弃大量注解和配置一起拥抱简洁。
License: Apache License 2.0
充分利用springboot自有注解来对文档进行描述的一款文档生成器。 让我们抛弃大量注解和配置一起拥抱简洁。
License: Apache License 2.0
如果controller被cglib代理 那么获取不到controller注解信息
ScanControllerSwagger
scan() 方法
// 组装swagger-api
Class<?> aClass = object.getValue().getClass();
// 如果有外层路径需要加上
String outPath = buildBaseUrl(aClass);
public String buildBaseUrl(Class<?> aClass) {
String basePath = "";
if (aClass.isAnnotationPresent(RequestMapping.class)) {
RequestMapping annotation = aClass.getAnnotation(RequestMapping.class);
if (annotation.value().length > 0) {
basePath = annotation.value()[0];
}
}
return basePath;
}
如果controller被代理了 那么outPath永远为空字符串
还应该通过 aClass.getSuperClass().isAnnotationPresent(RequestMapping.class) 判断
支持openapi3.0标准的文档格式,希望可以支持导入同步
我定义了一个R类,用于封装接口的返回对象,里面有error和data,data是泛型;
在controller中接口返回值使用 R、R,ydoc可以正常解析,但从yapi上查看的接口返回结构中User或Teacher谁在最后(swagger的definitions部分),页面展示的结构就是哪个对象的;
(将ydoc生产的swagger的json提取出来发现在 defintions结构中对R中data的定义只保留1个bean(要么是Teacher要么是User),而多个接口引用R的返回就导致展示返回值问题)
public R getUser(Long uId) {}
public R getTeacher(Long tId) {}
public R {
private T data;
.......
}
swagger json:
definitions部分:
"R":{"type": "object", "title": "R", "properties":{"data":{"description":"data", "$ref":"#/definitions/Teacher"}}}
接口定义部分:
paths:
/getUser
“responses”:
schema: $ref: "#/definitions/R"
/getTeacher
“responses”:
schema: $ref: "#/definitions/R"
您好,近期在掘金偶然看到您发布的《自定义Prometheus监控&Grafana画图》文章,内容写的很好,我们对这个内容也十分感兴趣,看得出您在研发这一块十分有经验,我们想邀请您和我们进行课程合作,将您的知识分享给更多人学习。邀请您制作的课程类型为收费课程,制作完毕后将进行上架销售,作者不仅会获得丰厚的收益分成,还会收获一批忠实的读者粉丝,并且制作课程的过程中,作者自身的技术能力也将会得到极大的提升。如果您有兴趣的话,欢迎添加我们的官方合作微信“shiyanloukecheng”,期待您的联系。
报错信息
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.autoconfigure.BackgroundPreinitializer
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:413)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:383)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:251)
at org.springframework.boot.SpringApplication.(SpringApplication.java:225)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.douyu.wsd.yapi.example.YApiApplication.main(YApiApplication.java:19)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/NativeDetector
at org.springframework.boot.autoconfigure.BackgroundPreinitializer.(BackgroundPreinitializer.java:71)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:409)
... 7 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.NativeDetector
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 14 more
public List queryTeacherList()
private Object getUserInfo
可以保存接口版本的变化历史吗? 从v1-v2 接口改变了什么. 如果有这个功能觉得会更好.
ydoc:
print: true
enable: true
host: http://yapi.smart-xwork.cn
swagger-native: false
导出的json无法导入到yapi
{"basePath":"/hrp","definitions":{},"info":{"description":"YDoc生成的RestfulApi文档","title":"YDoc(同时支持SwaggerUi和YApi的一款无侵入api文档生成器)","version":"last"},"paths":{},"schemes":["http"],"swagger":"2.0","tags":[{"description":"loginController","name":"loginController"},{"description":"basicAccountCategoryController","name":"basicAccountCategoryController"},{"description":"basicChargeCategoryController","name":"basicChargeCategoryController"},{"description":"basicChargeItemController","name":"basicChargeItemController"},{"description":"basicDeptMappingController","name":"basicDeptMappingController"},{"description":"basicIncomeItemController","name":"basicIncomeItemController"},{"description":"CABasicAccountItemController","name":"CABasicAccountItemController"},{"description":"CABasicAssetCategoryController","name":"CABasicAssetCategoryController"},{"description":"CABasicAssetItemController","name":"CABasicAssetItemController"},{"description":"CABasicCostClassifyController","name":"CABasicCostClassifyController"},{"description":"CABasicCostItemController","name":"CABasicCostItemController"},{"description":"CABasicMaterialCategoryController","name":"CABasicMaterialCategoryController"},{"description":"CABasicMaterialItemController","name":"CABasicMaterialItemController"},{"description":"CACommonDictionaryController","name":"CACommonDictionaryController"},{"description":"CADataPlatformController","name":"CADataPlatformController"},{"description":"helloController","name":"helloController"},{"description":"basicCitizenshipController","name":"basicCitizenshipController"},{"description":"basicDutyController","name":"basicDutyController"},{"description":"basicDutyLevelController","name":"basicDutyLevelController"},{"description":"basicDutySeriesController","name":"basicDutySeriesController"},{"description":"basicEducationController","name":"basicEducationController"},{"description":"basicEducationDegreeController","name":"basicEducationDegreeController"},{"description":"basicEducationTypeController","name":"basicEducationTypeController"},{"description":"basicPersontypeController","name":"basicPersontypeController"},{"description":"basicPoliticsController","name":"basicPoliticsController"},{"description":"basicPostLevelController","name":"basicPostLevelController"},{"description":"basicPostTypeController","name":"basicPostTypeController"},{"description":"basicPracticeController","name":"basicPracticeController"},{"description":"basicSalaryLevelController","name":"basicSalaryLevelController"},{"description":"basicTitleController","name":"basicTitleController"},{"description":"basicTitleLevelController","name":"basicTitleLevelController"},{"description":"basicTitleSeriesController","name":"basicTitleSeriesController"},{"description":"contractController","name":"contractController"},{"description":"humanCommonDictionaryController","name":"humanCommonDictionaryController"},{"description":"humanLeaveApplyController","name":"humanLeaveApplyController"},{"description":"personChangeController","name":"personChangeController"},{"description":"personRetireController","name":"personRetireController"},{"description":"staffController","name":"staffController"},{"description":"wagesFormulaController","name":"wagesFormulaController"},{"description":"wagesItemController","name":"wagesItemController"},{"description":"wagesPersonController","name":"wagesPersonController"},{"description":"wagesProcessController","name":"wagesProcessController"},{"description":"wagesProjectController","name":"wagesProjectController"},{"description":"wagesTaxController","name":"wagesTaxController"},{"description":"wagesTaxDetailController","name":"wagesTaxDetailController"},{"description":"accountingSchemeController","name":"accountingSchemeController"},{"description":"basicDepartmentController","name":"basicDepartmentController"},{"description":"basicDepartmentGradeController","name":"basicDepartmentGradeController"},{"description":"basicDepartmentTypeController","name":"basicDepartmentTypeController"},{"description":"basicItemController","name":"basicItemController"},{"description":"basicRbrvsController","name":"basicRbrvsController"},{"description":"basicTargetComputeController","name":"basicTargetComputeController"},{"description":"basicTargetController","name":"basicTargetController"},{"description":"basicWorkerController","name":"basicWorkerController"},{"description":"basicWorkerOwnershipController","name":"basicWorkerOwnershipController"},{"description":"classAttendController","name":"classAttendController"},{"description":"classItemController","name":"classItemController"},{"description":"commonDictionaryController","name":"commonDictionaryController"},{"description":"specialPeriodController","name":"specialPeriodController"},{"description":"computeFormulaController","name":"computeFormulaController"},{"description":"computeFormulaDetailController","name":"computeFormulaDetailController"},{"description":"computeFunctionController","name":"computeFunctionController"},{"description":"computeProcedureController","name":"computeProcedureController"},{"description":"computeSpecialController","name":"computeSpecialController"},{"description":"computeSpecialFormulaController","name":"computeSpecialFormulaController"},{"description":"computeSpecialProcedureController","name":"computeSpecialProcedureController"},{"description":"deptAttributeController","name":"deptAttributeController"},{"description":"deptTargetValueController","name":"deptTargetValueController"},{"description":"deptTypeSchemeController","name":"deptTypeSchemeController"},{"description":"distributeAutonomyItemController","name":"distributeAutonomyItemController"},{"description":"distributeFactorItemController","name":"distributeFactorItemController"},{"description":"distributeFactorRatioController","name":"distributeFactorRatioController"},{"description":"recordDrgController","name":"recordDrgController"},{"description":"standardDeptMappingController","name":"standardDeptMappingController"},{"description":"standardDrgBaController","name":"standardDrgBaController"},{"description":"standardDrgDeptController","name":"standardDrgDeptController"},{"description":"standardDrgWeightController","name":"standardDrgWeightController"},{"description":"standardItemDetailController","name":"standardItemDetailController"},{"description":"standardOperationComputeController","name":"standardOperationComputeController"},{"description":"standardOperationController","name":"standardOperationController"},{"description":"standardOperationCountController","name":"standardOperationCountController"},{"description":"standardOperationDetailController","name":"standardOperationDetailController"},{"description":"standardOperationMappingController","name":"standardOperationMappingController"},{"description":"standardPfController","name":"standardPfController"},{"description":"standardPfTypeController","name":"standardPfTypeController"},{"description":"standardRbrvsController","name":"standardRbrvsController"},{"description":"standardRbrvsTypeController","name":"standardRbrvsTypeController"},{"description":"standardRecordRbrvsController","name":"standardRecordRbrvsController"},{"description":"standardTimeController","name":"standardTimeController"},{"description":"taskControlController","name":"taskControlController"},{"description":"basicMenuController","name":"basicMenuController"},{"description":"basicModuleController","name":"basicModuleController"},{"description":"basicUnitController","name":"basicUnitController"},{"description":"companyController","name":"companyController"},{"description":"customColumnController","name":"customColumnController"},{"description":"departmentAttributeController","name":"departmentAttributeController"},{"description":"departmentClassifyController","name":"departmentClassifyController"},{"description":"departmentController","name":"departmentController"},{"description":"departmentMedinurseController","name":"departmentMedinurseController"},{"description":"departmentSharelevelController","name":"departmentSharelevelController"},{"description":"holidayController","name":"holidayController"},{"description":"parameterController","name":"parameterController"},{"description":"roleInfoController","name":"roleInfoController"},{"description":"roleMenuRightsController","name":"roleMenuRightsController"},{"description":"swapItemController","name":"swapItemController"},{"description":"swapSqlConfController","name":"swapSqlConfController"},{"description":"systemFileDownloadController","name":"systemFileDownloadController"},{"description":"systemFileUploadController","name":"systemFileUploadController"},{"description":"userInfoController","name":"userInfoController"}]}
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-10 20:43:07.611 ERROR 99056 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controllerSwagger' defined in class path resource [com/github/ydoc/config/AutoConfig.class]: Invocation of init method failed; nested exception is java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) [spring-boot-2.4.5.jar:2.4.5]
at com.cloud.tenmokucloud.DemoApplication.main(DemoApplication.java:12) [classes/:na]
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at com.github.ydoc.core.RequestTypeMatchingSwagger.deepObject(RequestTypeMatchingSwagger.java:517) ~[ydoc-spring-boot-starter-1.1.3.jar:1.1.3]
at com.github.ydoc.core.RequestTypeMatchingSwagger.returnBuild(RequestTypeMatchingSwagger.java:211) ~[ydoc-spring-boot-starter-1.1.3.jar:1.1.3]
at com.github.ydoc.core.RequestTypeMatchingSwagger.post(RequestTypeMatchingSwagger.java:388) ~[ydoc-spring-boot-starter-1.1.3.jar:1.1.3]
at com.github.ydoc.core.RequestTypeMatchingSwagger.matching(RequestTypeMatchingSwagger.java:47) ~[ydoc-spring-boot-starter-1.1.3.jar:1.1.3]
at com.github.ydoc.core.ScanControllerSwagger.scan(ScanControllerSwagger.java:85) ~[ydoc-spring-boot-starter-1.1.3.jar:1.1.3]
at com.github.ydoc.core.ScanControllerSwagger.afterPropertiesSet(ScanControllerSwagger.java:141) ~[ydoc-spring-boot-starter-1.1.3.jar:1.1.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.6.jar:5.3.6]
... 17 common frames omitted
下面是我的 pom 文件
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.4.5
com.cloud
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
<java.version>1.8</java.version>
<shiro-spring.version>1.6.0</shiro-spring.version>
<shiro-redis.version>3.3.1</shiro-redis.version>
<google.zxing.version>3.3.0</google.zxing.version>
<ydoc.version>1.1.3</ydoc.version>
<knife4j.version>2.0.7</knife4j.version>
<mybatis-plus-boot.version>3.1.2</mybatis-plus-boot.version>
<fastjson.version>1.2.59</fastjson.version>
<mybatis-generator.version>1.3.7</mybatis-generator.version>
<asm.version>3.3.1</asm.version>
<cglib-nodep.version>2.2.2</cglib-nodep.version>
<qiniu-java-sdk.version>7.2.23</qiniu-java-sdk.version>
<pinyin4j.version>2.5.1</pinyin4j.version>
<easypoi.version>4.4.0</easypoi.version>
<commons-codec.version>1.14</commons-codec.version>
<httpclient.version>4.5.3</httpclient.version>
<nacos.version>0.2.7</nacos.version>
org.springframework.boot
spring-boot-starter-web
<dependency>
<groupId>com.github.nobugboy</groupId>
<artifactId>ydoc-spring-boot-starter</artifactId>
<version>${ydoc.version}</version>
</dependency>
<!--mybatis generator-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis-generator.version}</version>
</dependency>
<!--db-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus-boot.version}</version>
</dependency>
<!--shiro 权限-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>${shiro-spring.version}</version>
</dependency>
<!-- shiro+redis缓存插件 -->
<dependency>
<groupId>org.crazycake</groupId>
<artifactId>shiro-redis</artifactId>
<version>${shiro-redis.version}</version>
</dependency>
<!-- cglib beancopy-->
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-util</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>${cglib-nodep.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- 七牛云对象存储 sdk -->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>${qiniu-java-sdk.version}</version>
</dependency>
<!--zxing start-->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>${google.zxing.version}</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>${google.zxing.version}</version>
</dependency>
<!--zxing end-->
<!--https://liuyueyi.github.io/quick-media-->
<!-- <dependency>
<groupId>com.github.hui.media</groupId>
<artifactId>qrcode-plugin</artifactId>
<version>2.5.1</version>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<!-- codec 加密 -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-crypto</artifactId>
<version>5.7.2</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.65</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
响应泛型对象:
public class ResultModel implements Serializable {
private int code;
private String text;
private T data;
}
Yapi显示:
code | integer | 非必须 | | http状态码 |
data | object | 非必须 | | data | 备注: data
text | string | 非必须 | | 描述
问题如下:
data泛型是个VO,yapi上不显示VO以下属性,请问这个怎么解决?
问题控制器代码如下:这样设置就无法生成
@RestController
@RequestMapping("test/")
public class TestController {
@GetMapping(value = "/get/{id}")
public User test(@ParamDesc("id") @PathVariable(value = "id") String id){
User u = new User();
return u;
}
@GetMapping(value = "/last")
public User test(User user){
return user;
}
@PostMapping(value = "/post")
public User test1(@requestbody User user){
System.out.println(user);
return user;
}
}
Originally posted by @HelloZYHs in #2 (comment)
我的项目从未引用过接口文档,今天刷B站所以来到了这里,按文档(版本1.1.6.final)做,跑不起来。看文档、视频、议题,无数次调试想找到创建实例时在哪里失败,一路断点找原因
ID | Descripttion | Screenshot |
---|---|---|
1 | RequestTypeMatchingSwagger.matching(api); 追到了这行,因为此后五六条栈帧会跳转 Spring 容器代理,大概说 BeanFactory 创建单例失败了,向上层抛出 NPE。这段代码,它似乎在扫描我项目文件中符合 Swagger 注解类型的特征,现在找到 0 个,匹配 0,就销毁 Bean 单例了。 |
![]() |
2 | 所以为什么这里 DocApi 类型的 api 是零个值呢?顺着 api 的值去找线索:比如请求路径 outPath=/order/mqmessage 找到控制器,找到 update 方法。这些是人人开源插件自动生成的代码,请求类型注解都是 @RequestMapping 。 |
![]() |
3 | 现在点进匹配方法 matching 看匹配规则,似乎它扫描控制器的所有注解后,在做统计。由于上一步 DocApi 为空(size=0),获取不到 api 的方法名称,也不能添加路径赋值。 |
![]() |
4 | 那么,我们回到上一步,具体怎么构造 / 更新 DocApi 的呢?如图,看上去每个属性被参数赋值,但返回后就 size=0 ,api 点开看不到值了。实际步进每一行 set 语句,发现赋值方法都失效了,DOC_API 仍是空值(空构造器)。推测原因:final static 修饰的属性,只能手动赋值一次(仅限两种方式:声明时赋值,或静态代码块中赋值)。上面图 1 中第 27 行语句首次调用 DOC_API ,意味着通过无参构造方法实例化,获得空值(空构造器),已经消耗了一次机会,它不能被修改了。参考文章 Java 中为 final 变量赋值的几种方式 |
![]() |
我的配置
ydoc:
enable: true
host: http://111.222.333.444:40001
token: 81***6a
headers:
sping:
mvc:
date-format: yyyy-MM-dd HH:mm:ss
pathmatch:
matching-strategy: ant_path_matcher
备注
@EnableSwagger2
启动类注解,有无都会报错headers
:空值,有无此属性都会报错。来自文章评论区pathmatch
:有无此属性都会报错。来自议题启动日志
C:\Users\miozus\.jdks\corretto-1.8.0_322\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:60731,suspend=y,server=n -Dvisualvm.id=8949864274300 -Xmx100m -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:E:\JetBrains\Toolbox\apps\IDEA-U\ch-1\221.4165.146\plugins\java\lib\rt\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\charsets.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\access-bridge-64.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\cldrdata.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\dnsns.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\jaccess.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\jfxrt.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\localedata.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\nashorn.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\sunec.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\sunjce_provider.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\sunmscapi.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\sunpkcs11.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\ext\zipfs.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\jce.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\jfr.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\jfxswt.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\jsse.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\management-agent.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\resources.jar;C:\Users\miozus\.jdks\corretto-1.8.0_322\jre\lib\rt.jar;E:\projects\IdeaProjects\gulimall\gulimall-order\target\classes;D:\server\maven\repository\com\alipay\sdk\alipay-sdk-java\4.22.30.ALL\alipay-sdk-java-4.22.30.ALL.jar;D:\server\maven\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;D:\server\maven\repository\com\alibaba\fastjson\1.2.78\fastjson-1.2.78.jar;D:\server\maven\repository\org\bouncycastle\bcprov-jdk15on\1.62\bcprov-jdk15on-1.62.jar;D:\server\maven\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;D:\server\maven\repository\xml-apis\xml-apis\1.0.b2\xml-apis-1.0.b2.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-data-redis\2.3.2.RELEASE\spring-boot-starter-data-redis-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter\2.3.2.RELEASE\spring-boot-starter-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot\2.3.2.RELEASE\spring-boot-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-autoconfigure\2.3.2.RELEASE\spring-boot-autoconfigure-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-logging\2.3.2.RELEASE\spring-boot-starter-logging-2.3.2.RELEASE.jar;D:\server\maven\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\server\maven\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\server\maven\repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;D:\server\maven\repository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;D:\server\maven\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\server\maven\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\server\maven\repository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\server\maven\repository\org\springframework\data\spring-data-redis\2.3.2.RELEASE\spring-data-redis-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\data\spring-data-keyvalue\2.3.2.RELEASE\spring-data-keyvalue-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\data\spring-data-commons\2.3.2.RELEASE\spring-data-commons-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-tx\5.2.8.RELEASE\spring-tx-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-oxm\5.2.8.RELEASE\spring-oxm-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-aop\5.2.8.RELEASE\spring-aop-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-context-support\5.2.8.RELEASE\spring-context-support-5.2.8.RELEASE.jar;D:\server\maven\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\server\maven\repository\io\lettuce\lettuce-core\5.3.2.RELEASE\lettuce-core-5.3.2.RELEASE.jar;D:\server\maven\repository\io\netty\netty-common\4.1.51.Final\netty-common-4.1.51.Final.jar;D:\server\maven\repository\io\netty\netty-handler\4.1.51.Final\netty-handler-4.1.51.Final.jar;D:\server\maven\repository\io\netty\netty-resolver\4.1.51.Final\netty-resolver-4.1.51.Final.jar;D:\server\maven\repository\io\netty\netty-buffer\4.1.51.Final\netty-buffer-4.1.51.Final.jar;D:\server\maven\repository\io\netty\netty-codec\4.1.51.Final\netty-codec-4.1.51.Final.jar;D:\server\maven\repository\io\netty\netty-transport\4.1.51.Final\netty-transport-4.1.51.Final.jar;D:\server\maven\repository\io\projectreactor\reactor-core\3.3.8.RELEASE\reactor-core-3.3.8.RELEASE.jar;D:\server\maven\repository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;D:\server\maven\repository\org\springframework\session\spring-session-data-redis\2.3.0.RELEASE\spring-session-data-redis-2.3.0.RELEASE.jar;D:\server\maven\repository\org\springframework\session\spring-session-core\2.3.0.RELEASE\spring-session-core-2.3.0.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-jcl\5.2.8.RELEASE\spring-jcl-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-amqp\2.3.2.RELEASE\spring-boot-starter-amqp-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-messaging\5.2.8.RELEASE\spring-messaging-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-beans\5.2.8.RELEASE\spring-beans-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\amqp\spring-rabbit\2.2.9.RELEASE\spring-rabbit-2.2.9.RELEASE.jar;D:\server\maven\repository\com\rabbitmq\amqp-client\5.9.0\amqp-client-5.9.0.jar;D:\server\maven\repository\org\springframework\amqp\spring-amqp\2.2.9.RELEASE\spring-amqp-2.2.9.RELEASE.jar;D:\server\maven\repository\org\springframework\retry\spring-retry\1.2.5.RELEASE\spring-retry-1.2.5.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-context\5.2.8.RELEASE\spring-context-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-thymeleaf\2.3.2.RELEASE\spring-boot-starter-thymeleaf-2.3.2.RELEASE.jar;D:\server\maven\repository\org\thymeleaf\thymeleaf-spring5\3.0.11.RELEASE\thymeleaf-spring5-3.0.11.RELEASE.jar;D:\server\maven\repository\org\thymeleaf\thymeleaf\3.0.11.RELEASE\thymeleaf-3.0.11.RELEASE.jar;D:\server\maven\repository\org\attoparser\attoparser\2.0.5.RELEASE\attoparser-2.0.5.RELEASE.jar;D:\server\maven\repository\org\unbescape\unbescape\1.1.6.RELEASE\unbescape-1.1.6.RELEASE.jar;D:\server\maven\repository\org\thymeleaf\extras\thymeleaf-extras-java8time\3.0.4.RELEASE\thymeleaf-extras-java8time-3.0.4.RELEASE.jar;E:\projects\IdeaProjects\gulimall\gulimall-common\target\classes;D:\server\maven\repository\cn\hutool\hutool-all\5.7.20\hutool-all-5.7.20.jar;D:\server\maven\repository\com\baomidou\mybatis-plus-boot-starter\3.3.1\mybatis-plus-boot-starter-3.3.1.jar;D:\server\maven\repository\com\baomidou\mybatis-plus\3.3.1\mybatis-plus-3.3.1.jar;D:\server\maven\repository\com\baomidou\mybatis-plus-extension\3.3.1\mybatis-plus-extension-3.3.1.jar;D:\server\maven\repository\com\baomidou\mybatis-plus-core\3.3.1\mybatis-plus-core-3.3.1.jar;D:\server\maven\repository\com\baomidou\mybatis-plus-annotation\3.3.1\mybatis-plus-annotation-3.3.1.jar;D:\server\maven\repository\com\github\jsqlparser\jsqlparser\3.1\jsqlparser-3.1.jar;D:\server\maven\repository\org\mybatis\mybatis\3.5.3\mybatis-3.5.3.jar;D:\server\maven\repository\org\mybatis\mybatis-spring\2.0.3\mybatis-spring-2.0.3.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-jdbc\2.3.2.RELEASE\spring-boot-starter-jdbc-2.3.2.RELEASE.jar;D:\server\maven\repository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;D:\server\maven\repository\org\springframework\spring-jdbc\5.2.8.RELEASE\spring-jdbc-5.2.8.RELEASE.jar;D:\server\maven\repository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar;D:\server\maven\repository\mysql\mysql-connector-java\8.0.21\mysql-connector-java-8.0.21.jar;D:\server\maven\repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;D:\server\maven\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\server\maven\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\server\maven\repository\org\hibernate\validator\hibernate-validator\6.1.5.Final\hibernate-validator-6.1.5.Final.jar;D:\server\maven\repository\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;D:\server\maven\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;D:\server\maven\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\server\maven\repository\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-discovery\2.2.5.RELEASE\spring-cloud-starter-alibaba-nacos-discovery-2.2.5.RELEASE.jar;D:\server\maven\repository\com\alibaba\cloud\spring-cloud-alibaba-commons\2.2.5.RELEASE\spring-cloud-alibaba-commons-2.2.5.RELEASE.jar;D:\server\maven\repository\com\alibaba\nacos\nacos-client\1.4.1\nacos-client-1.4.1.jar;D:\server\maven\repository\com\alibaba\nacos\nacos-common\1.4.1\nacos-common-1.4.1.jar;D:\server\maven\repository\commons-io\commons-io\2.2\commons-io-2.2.jar;D:\server\maven\repository\org\apache\httpcomponents\httpasyncclient\4.1.4\httpasyncclient-4.1.4.jar;D:\server\maven\repository\org\apache\httpcomponents\httpcore-nio\4.4.13\httpcore-nio-4.4.13.jar;D:\server\maven\repository\com\alibaba\nacos\nacos-api\1.4.1\nacos-api-1.4.1.jar;D:\server\maven\repository\com\google\guava\guava\29.0-jre\guava-29.0-jre.jar;D:\server\maven\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;D:\server\maven\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;D:\server\maven\repository\org\checkerframework\checker-qual\2.11.1\checker-qual-2.11.1.jar;D:\server\maven\repository\com\google\errorprone\error_prone_annotations\2.3.4\error_prone_annotations-2.3.4.jar;D:\server\maven\repository\com\google\j2objc\j2objc-annotations\1.3\j2objc-annotations-1.3.jar;D:\server\maven\repository\commons-codec\commons-codec\1.14\commons-codec-1.14.jar;D:\server\maven\repository\com\fasterxml\jackson\core\jackson-core\2.11.1\jackson-core-2.11.1.jar;D:\server\maven\repository\io\prometheus\simpleclient\0.5.0\simpleclient-0.5.0.jar;D:\server\maven\repository\com\alibaba\spring\spring-context-support\1.0.10\spring-context-support-1.0.10.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-context\2.2.4.RELEASE\spring-cloud-context-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.2.4.RELEASE\spring-cloud-starter-netflix-ribbon-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.2.4.RELEASE\spring-cloud-starter-netflix-archaius-2.2.4.RELEASE.jar;D:\server\maven\repository\com\netflix\ribbon\ribbon\2.3.0\ribbon-2.3.0.jar;D:\server\maven\repository\com\netflix\ribbon\ribbon-transport\2.3.0\ribbon-transport-2.3.0.jar;D:\server\maven\repository\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\server\maven\repository\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\server\maven\repository\javax\inject\javax.inject\1\javax.inject-1.jar;D:\server\maven\repository\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\server\maven\repository\com\netflix\ribbon\ribbon-core\2.3.0\ribbon-core-2.3.0.jar;D:\server\maven\repository\com\netflix\ribbon\ribbon-httpclient\2.3.0\ribbon-httpclient-2.3.0.jar;D:\server\maven\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\server\maven\repository\org\apache\httpcomponents\httpclient\4.5.12\httpclient-4.5.12.jar;D:\server\maven\repository\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\server\maven\repository\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\server\maven\repository\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\server\maven\repository\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\server\maven\repository\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;D:\server\maven\repository\com\netflix\netflix-commons\netflix-commons-util\0.3.0\netflix-commons-util-0.3.0.jar;D:\server\maven\repository\com\netflix\ribbon\ribbon-loadbalancer\2.3.0\ribbon-loadbalancer-2.3.0.jar;D:\server\maven\repository\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\server\maven\repository\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;D:\server\maven\repository\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-config\2.2.5.RELEASE\spring-cloud-starter-alibaba-nacos-config-2.2.5.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-web\5.2.8.RELEASE\spring-web-5.2.8.RELEASE.jar;D:\server\maven\repository\com\github\nobugboy\ydoc-spring-boot-starter\1.1.6.final\ydoc-spring-boot-starter-1.1.6.final.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-mail\2.3.2.RELEASE\spring-boot-starter-mail-2.3.2.RELEASE.jar;D:\server\maven\repository\com\sun\mail\jakarta.mail\1.6.5\jakarta.mail-1.6.5.jar;D:\server\maven\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;D:\server\maven\repository\io\springfox\springfox-swagger2\2.9.2\springfox-swagger2-2.9.2.jar;D:\server\maven\repository\io\swagger\swagger-annotations\1.5.20\swagger-annotations-1.5.20.jar;D:\server\maven\repository\io\swagger\swagger-models\1.5.20\swagger-models-1.5.20.jar;D:\server\maven\repository\io\springfox\springfox-spi\2.9.2\springfox-spi-2.9.2.jar;D:\server\maven\repository\io\springfox\springfox-core\2.9.2\springfox-core-2.9.2.jar;D:\server\maven\repository\io\springfox\springfox-schema\2.9.2\springfox-schema-2.9.2.jar;D:\server\maven\repository\io\springfox\springfox-swagger-common\2.9.2\springfox-swagger-common-2.9.2.jar;D:\server\maven\repository\io\springfox\springfox-spring-web\2.9.2\springfox-spring-web-2.9.2.jar;D:\server\maven\repository\org\springframework\plugin\spring-plugin-core\1.2.0.RELEASE\spring-plugin-core-1.2.0.RELEASE.jar;D:\server\maven\repository\org\springframework\plugin\spring-plugin-metadata\1.2.0.RELEASE\spring-plugin-metadata-1.2.0.RELEASE.jar;D:\server\maven\repository\org\mapstruct\mapstruct\1.2.0.Final\mapstruct-1.2.0.Final.jar;D:\server\maven\repository\com\github\nobugboy\lucky-ui\release-1.0.2\lucky-ui-release-1.0.2.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-web\2.3.2.RELEASE\spring-boot-starter-web-2.3.2.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-json\2.3.2.RELEASE\spring-boot-starter-json-2.3.2.RELEASE.jar;D:\server\maven\repository\com\fasterxml\jackson\core\jackson-databind\2.11.1\jackson-databind-2.11.1.jar;D:\server\maven\repository\com\fasterxml\jackson\core\jackson-annotations\2.11.1\jackson-annotations-2.11.1.jar;D:\server\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.1\jackson-datatype-jdk8-2.11.1.jar;D:\server\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.1\jackson-datatype-jsr310-2.11.1.jar;D:\server\maven\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.1\jackson-module-parameter-names-2.11.1.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-tomcat\2.3.2.RELEASE\spring-boot-starter-tomcat-2.3.2.RELEASE.jar;D:\server\maven\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.37\tomcat-embed-core-9.0.37.jar;D:\server\maven\repository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;D:\server\maven\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.37\tomcat-embed-websocket-9.0.37.jar;D:\server\maven\repository\org\springframework\spring-webmvc\5.2.8.RELEASE\spring-webmvc-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\spring-expression\5.2.8.RELEASE\spring-expression-5.2.8.RELEASE.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-starter-openfeign\2.2.4.RELEASE\spring-cloud-starter-openfeign-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-starter\2.2.4.RELEASE\spring-cloud-starter-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\security\spring-security-rsa\1.0.9.RELEASE\spring-security-rsa-1.0.9.RELEASE.jar;D:\server\maven\repository\org\bouncycastle\bcpkix-jdk15on\1.64\bcpkix-jdk15on-1.64.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-openfeign-core\2.2.4.RELEASE\spring-cloud-openfeign-core-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-netflix-ribbon\2.2.4.RELEASE\spring-cloud-netflix-ribbon-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-netflix-archaius\2.2.4.RELEASE\spring-cloud-netflix-archaius-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\boot\spring-boot-starter-aop\2.3.2.RELEASE\spring-boot-starter-aop-2.3.2.RELEASE.jar;D:\server\maven\repository\org\aspectj\aspectjweaver\1.9.6\aspectjweaver-1.9.6.jar;D:\server\maven\repository\io\github\openfeign\form\feign-form-spring\3.8.0\feign-form-spring-3.8.0.jar;D:\server\maven\repository\io\github\openfeign\form\feign-form\3.8.0\feign-form-3.8.0.jar;D:\server\maven\repository\commons-fileupload\commons-fileupload\1.4\commons-fileupload-1.4.jar;D:\server\maven\repository\org\springframework\cloud\spring-cloud-commons\2.2.4.RELEASE\spring-cloud-commons-2.2.4.RELEASE.jar;D:\server\maven\repository\org\springframework\security\spring-security-crypto\5.3.3.RELEASE\spring-security-crypto-5.3.3.RELEASE.jar;D:\server\maven\repository\io\github\openfeign\feign-core\10.10.1\feign-core-10.10.1.jar;D:\server\maven\repository\io\github\openfeign\feign-slf4j\10.10.1\feign-slf4j-10.10.1.jar;D:\server\maven\repository\io\github\openfeign\feign-hystrix\10.10.1\feign-hystrix-10.10.1.jar;D:\server\maven\repository\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;D:\server\maven\repository\com\google\code\findbugs\jsr305\3.0.1\jsr305-3.0.1.jar;D:\server\maven\repository\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\server\maven\repository\com\netflix\hystrix\hystrix-core\1.5.18\hystrix-core-1.5.18.jar;D:\server\maven\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\server\maven\repository\net\bytebuddy\byte-buddy\1.10.13\byte-buddy-1.10.13.jar;D:\server\maven\repository\org\springframework\spring-core\5.2.8.RELEASE\spring-core-5.2.8.RELEASE.jar;E:\JetBrains\Toolbox\apps\IDEA-U\ch-1\221.4165.146\lib\idea_rt.jar cn.miozus.gulimall.order.GulimallOrderApplication
Connected to the target VM, address: '127.0.0.1:60731', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.2.RELEASE)
2022-02-18 20:29:21.439 INFO 5900 --- [ main] c.a.n.c.c.impl.LocalConfigInfoProcessor : LOCAL_SNAPSHOT_PATH:C:\Users\miozus\nacos\config
2022-02-18 20:29:21.470 INFO 5900 --- [ main] c.a.nacos.client.config.impl.Limiter : limitTime:5.0
2022-02-18 20:29:21.639 INFO 5900 --- [ main] c.a.nacos.client.config.utils.JvmUtil : isMultiInstance:false
2022-02-18 20:29:22.704 WARN 5900 --- [ main] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[gulimall-order] & group[DEFAULT_GROUP]
2022-02-18 20:29:22.732 WARN 5900 --- [ main] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[gulimall-order.properties] & group[DEFAULT_GROUP]
2022-02-18 20:29:22.732 INFO 5900 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-gulimall-order.properties,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-gulimall-order,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-ydoc.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-cache.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-pay.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-feign.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-redis.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-threadpool.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-rabbitmq.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-other.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-mybatis.yml,pro'}, BootstrapPropertySource {name='bootstrapProperties-datasource.yml,pro'}]
2022-02-18 20:29:22.763 INFO 5900 --- [ main] c.m.g.order.GulimallOrderApplication : No active profile set, falling back to default profiles: default
2022-02-18 20:29:23.221 INFO 5900 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2022-02-18 20:29:23.221 INFO 5900 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2022-02-18 20:29:23.237 INFO 5900 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8ms. Found 0 Redis repository interfaces.
2022-02-18 20:29:23.394 INFO 5900 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=bed9f933-1953-3f2b-a74e-16adf5f487bc
2022-02-18 20:29:23.815 INFO 5900 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-02-18 20:29:23.831 INFO 5900 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-02-18 20:29:23.831 INFO 5900 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2022-02-18 20:29:23.909 INFO 5900 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-02-18 20:29:23.909 INFO 5900 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1130 ms
_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\
/ |
3.3.1
2022-02-18 20:29:26.833 WARN 5900 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2022-02-18 20:29:26.833 INFO 5900 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2022-02-18 20:29:26.837 WARN 5900 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2022-02-18 20:29:26.837 INFO 5900 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2022-02-18 20:29:27.401 INFO 5900 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'Nacos-Watch-Task-Scheduler'
_ _ ____ _____ ___
( \/ )( _ \( _ )/ __)
\ / )(_) ))(_)(( (__
(__) (____/(_____)\___)
v1.1.6.final
2022-02-18 20:41:23.033 WARN 5900 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controllerSwagger' defined in class path resource [com/github/ydoc/config/AutoConfig.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException
2022-02-18 20:41:23.033 WARN 5900 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Destroy method 'close' on bean with name 'nacosServiceRegistry' threw an exception: java.lang.NullPointerException
2022-02-18 20:41:23.343 INFO 5900 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-02-18 20:41:23.457 INFO 5900 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-18 20:41:23.488 ERROR 5900 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controllerSwagger' defined in class path resource [com/github/ydoc/config/AutoConfig.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at cn.miozus.gulimall.order.GulimallOrderApplication.main(GulimallOrderApplication.java:26) [classes/:na]
Caused by: java.lang.NullPointerException: null
at com.github.ydoc.core.handler.api.RequestHandler.generateApi(RequestHandler.java:16) ~[ydoc-spring-boot-starter-1.1.6.final.jar:1.1.6.final]
at com.github.ydoc.core.handler.api.RequestHandler.generateApi(RequestHandler.java:10) ~[ydoc-spring-boot-starter-1.1.6.final.jar:1.1.6.final]
at com.github.ydoc.core.RequestTypeMatchingSwagger.matching(RequestTypeMatchingSwagger.java:67) ~[ydoc-spring-boot-starter-1.1.6.final.jar:1.1.6.final]
at com.github.ydoc.core.ScanControllerSwagger.scan(ScanControllerSwagger.java:105) ~[ydoc-spring-boot-starter-1.1.6.final.jar:1.1.6.final]
at com.github.ydoc.core.ScanControllerSwagger.afterPropertiesSet(ScanControllerSwagger.java:163) ~[ydoc-spring-boot-starter-1.1.6.final.jar:1.1.6.final]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
... 17 common frames omitted
2022-02-18 20:41:24.247 WARN 5900 --- [ Thread-2] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Start destroying common HttpClient
2022-02-18 20:41:24.247 WARN 5900 --- [ Thread-2] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Destruction of the end
Disconnected from the target VM, address: '127.0.0.1:60731', transport: 'socket'
Process finished with exit code 1
项目依赖 Maven
<!-- 公共依赖(全部版本)-->
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<lombok.version>1.18.22</lombok.version>
<mysql.version>8.0.26</mysql.version>
<mybatis.plus.boot.version>3.3.1</mybatis.plus.boot.version>
<servlet.api.version>2.5</servlet.api.version>
<commons.lang.version>2.6</commons.lang.version>
<httpcore.version>4.4.15</httpcore.version>
<fastjson.version>1.2.79</fastjson.version>
<validation.api.version>2.0.1.Final</validation.api.version>
<hutool.all.version>5.7.20</hutool.all.version>
<hibernate.validator.version>7.0.1.Final</hibernate.validator.version>
<spring.web.version>5.2.8.RELEASE</spring.web.version>
<ydoc.spring.boot.starter.version>1.1.6.final</ydoc.spring.boot.starter.version>
</properties>
<!-- 订单微服务依赖-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cn.miozus</groupId>
<artifactId>gulimall-order</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gulimall-order</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
<spring-cloud.version>Hoxton.SR7</spring-cloud.version>
</properties>
<dependencies>
<!-- 支付宝SDK -->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.22.30.ALL</version>
</dependency>
<!-- 分布式缓存 redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- 统一储存 session 跨域共享 -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<!-- 消息队列 RabbitMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!-- 前端页面渲染模板 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- 公共依赖包 -->
<dependency>
<groupId>cn.miozus.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 初始勾选的两个依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
测试时发现的 等下一个版本会修复
如果返回结果是 泛型且嵌套List时,会报类型转换异常。
示例:
定义个ResultEntity 如下
private class ResultEntity<T> {
private String code;
private String message;
private T rows;
}
定义一个接口
@GetMapping("/test")
public ResultEntity<List<Map<String,String>>(){
return null;
}
这种情况下会报
Caused by: java.lang.ClassCastException: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to class java.lang.Class (sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl and java.lang.Class are in module java.base of loader 'bootstrap')
at com.github.ydoc.core.Core.deepObject(Core.java:135) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.strategy.AbstractStrategy.deepObject(AbstractStrategy.java:56) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.strategy.AbstractStrategy.baseResponse(AbstractStrategy.java:154) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.strategy.AbstractHandler.processResponse(AbstractHandler.java:46) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.strategy.AbstractHandler.init(AbstractHandler.java:36) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.handler.api.PostHandler.generateApi(PostHandler.java:18) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.handler.api.PostHandler.generateApi(PostHandler.java:11) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.StrategySelector.matchAndGenerateApi(StrategySelector.java:33) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.ScanApi.scan(ScanApi.java:111) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at com.github.ydoc.core.ScanApi.afterPropertiesSet(ScanApi.java:210) ~[ydoc-spring-boot-starter-1.1.7.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.17.jar:5.3.17]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.17.jar:5.3.17]
... 16 common frames omitted
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:601)
at java.lang.Long.valueOf(Long.java:803)
at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.alibaba.fastjson.util.FieldInfo.get(FieldInfo.java:571)
at com.alibaba.fastjson.serializer.FieldSerializer.getPropertyValueDirect(FieldSerializer.java:143)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:284)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:154)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:360)
at com.alibaba.fastjson.serializer.ASMSerializer_17_Operation.write(Unknown Source)
at com.alibaba.fastjson.serializer.ASMSerializer_16_Path.write(Unknown Source)
at com.alibaba.fastjson.serializer.MapSerializer.write(MapSerializer.java:271)
at com.alibaba.fastjson.serializer.MapSerializer.write(MapSerializer.java:44)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:360)
at com.alibaba.fastjson.serializer.ASMSerializer_1_Swagger.write(Unknown Source)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:312)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:793)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:731)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:688)
at com.github.ydoc.core.ScanControllerSwagger.run(ScanControllerSwagger.java:155)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:771)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:755)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controllerSwagger' defined in class path resource [com/github/ydoc/config/AutoConfig.class]: Invocation of init method failed; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.reflect.InvocationHandler java.lang.reflect.Proxy.h accessible: module java.base does not "opens java.lang.reflect" to unnamed module @16e7dcfd
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.waitingresult.Main.main(Main.java:9)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.reflect.InvocationHandler java.lang.reflect.Proxy.h accessible: module java.base does not "opens java.lang.reflect" to unnamed module @16e7dcfd
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at com.github.ydoc.core.Core.proxyToTargetClassName(Core.java:340)
at com.github.ydoc.core.StrategySelector.matchAndGenerateApi(StrategySelector.java:32)
at com.github.ydoc.core.ScanApi.scan(ScanApi.java:111)
at com.github.ydoc.core.ScanApi.afterPropertiesSet(ScanApi.java:210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
... 16 more
需求场景:
当前业务结构 controller > 不同需求包路径 > b端 | c 端
controller:
name:
c:
b:
所以想指定到name 层级, 每个需求版本都生成指定包和子包路径下的controller类接口文档
报错信息
你好 我将问题描述写在了这里
https://ask.csdn.net/questions/7546224?weChatOA=
求大神解答
1.缺少对@RequestParam
、@PatchMapping
的支持;
2.不应该写死application/json
,而是取org.springframework.web.bind.annotation.RequestMapping#consumes
;
private static void post(String name, String path, JSONObject api, Method method, String outPath, String tag) {
// 方法对象
JSONObject apiMethod = Factory.get();
if (api.containsKey(outPath + path)) {
// 路径已经存在
apiMethod = (JSONObject) api.get(outPath + path);
} else {
api.put(outPath + path, apiMethod);
}
// body
JSONObject content = Factory.get();
apiMethod.put("post", content);
content.put("tags", Collections.singletonList(tag));
// restfulApi接口的描述/功能
content.put("summary", name);
content.put("description", name);
//fixme 这里不应该写死,而是取org.springframework.web.bind.annotation.RequestMapping#consumes,取不到才是application/json,有3处这样的地方
content.put("consumes", Collections.singleton("application/json"));
// 处理get参数 1.如果不是pojo则必须带上@RequestParam用来获取参数描述信息
List<JSONObject> parametersJson = new ArrayList<>();
addHeader(parametersJson);
content.put("parameters", parametersJson);
returnBuild(method, content);
// restfulApi接口的描述/功能
baseRequestBody(method.getParameters(), parametersJson);
}
3.com.github.ydoc.core.RequestTypeMatchingSwagger
里有很多重复代码,建议用org.springframework.core.annotation.AnnotationUtils#findAnnotation(java.lang.reflect.Method, java.lang.Class<A>)
or 模板模式+策略模式
进行重构;
"C:\Program Files (x86)\Java\jdk-9\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59760,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:C:\Users\w.IntelliJIdea2019.2\system\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "D:\IdeaProjects\spider-man\target\classes;D:\Maven_Repository\org\jsoup\jsoup\1.13.1\jsoup-1.13.1.jar;D:\Maven_Repository\cn\wanghaomiao\JsoupXpath\2.4.3\JsoupXpath-2.4.3.jar;D:\Maven_Repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;D:\Maven_Repository\org\antlr\antlr4-runtime\4.7.2\antlr4-runtime-4.7.2.jar;D:\Maven_Repository\org\slf4j\slf4j-api\1.7.31\slf4j-api-1.7.31.jar;D:\Maven_Repository\cn\afterturn\easypoi-base\4.2.0\easypoi-base-4.2.0.jar;D:\Maven_Repository\org\apache\poi\poi\4.1.1\poi-4.1.1.jar;D:\Maven_Repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;D:\Maven_Repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;D:\Maven_Repository\org\apache\commons\commons-math3\3.6.1\commons-math3-3.6.1.jar;D:\Maven_Repository\org\apache\poi\poi-ooxml\4.1.1\poi-ooxml-4.1.1.jar;D:\Maven_Repository\org\apache\commons\commons-compress\1.19\commons-compress-1.19.jar;D:\Maven_Repository\com\github\virtuald\curvesapi\1.06\curvesapi-1.06.jar;D:\Maven_Repository\org\apache\poi\poi-ooxml-schemas\4.1.1\poi-ooxml-schemas-4.1.1.jar;D:\Maven_Repository\org\apache\xmlbeans\xmlbeans\3.1.0\xmlbeans-3.1.0.jar;D:\Maven_Repository\ognl\ognl\3.2.6\ognl-3.2.6.jar;D:\Maven_Repository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;D:\Maven_Repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\Maven_Repository\cn\afterturn\easypoi-annotation\4.2.0\easypoi-annotation-4.2.0.jar;D:\Maven_Repository\cn\hutool\hutool-all\5.7.5\hutool-all-5.7.5.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-starter-web\2.5.2\spring-boot-starter-web-2.5.2.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-starter\2.5.2\spring-boot-starter-2.5.2.jar;D:\Maven_Repository\org\springframework\boot\spring-boot\2.5.2\spring-boot-2.5.2.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-starter-logging\2.5.2\spring-boot-starter-logging-2.5.2.jar;D:\Maven_Repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\Maven_Repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\Maven_Repository\org\apache\logging\log4j\log4j-to-slf4j\2.14.1\log4j-to-slf4j-2.14.1.jar;D:\Maven_Repository\org\apache\logging\log4j\log4j-api\2.14.1\log4j-api-2.14.1.jar;D:\Maven_Repository\org\slf4j\jul-to-slf4j\1.7.31\jul-to-slf4j-1.7.31.jar;D:\Maven_Repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\Maven_Repository\org\yaml\snakeyaml\1.28\snakeyaml-1.28.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-starter-json\2.5.2\spring-boot-starter-json-2.5.2.jar;D:\Maven_Repository\com\fasterxml\jackson\core\jackson-databind\2.12.3\jackson-databind-2.12.3.jar;D:\Maven_Repository\com\fasterxml\jackson\core\jackson-annotations\2.12.3\jackson-annotations-2.12.3.jar;D:\Maven_Repository\com\fasterxml\jackson\core\jackson-core\2.12.3\jackson-core-2.12.3.jar;D:\Maven_Repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.12.3\jackson-datatype-jdk8-2.12.3.jar;D:\Maven_Repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.12.3\jackson-datatype-jsr310-2.12.3.jar;D:\Maven_Repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.12.3\jackson-module-parameter-names-2.12.3.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-starter-tomcat\2.5.2\spring-boot-starter-tomcat-2.5.2.jar;D:\Maven_Repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.48\tomcat-embed-core-9.0.48.jar;D:\Maven_Repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.48\tomcat-embed-el-9.0.48.jar;D:\Maven_Repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.48\tomcat-embed-websocket-9.0.48.jar;D:\Maven_Repository\org\springframework\spring-web\5.3.8\spring-web-5.3.8.jar;D:\Maven_Repository\org\springframework\spring-beans\5.3.8\spring-beans-5.3.8.jar;D:\Maven_Repository\org\springframework\spring-webmvc\5.3.8\spring-webmvc-5.3.8.jar;D:\Maven_Repository\org\springframework\spring-aop\5.3.8\spring-aop-5.3.8.jar;D:\Maven_Repository\org\springframework\spring-context\5.3.8\spring-context-5.3.8.jar;D:\Maven_Repository\org\springframework\spring-expression\5.3.8\spring-expression-5.3.8.jar;D:\Maven_Repository\com\github\nobugboy\ydoc-spring-boot-starter\1.1.2\ydoc-spring-boot-starter-1.1.2.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-autoconfigure\2.5.2\spring-boot-autoconfigure-2.5.2.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-starter-mail\2.5.2\spring-boot-starter-mail-2.5.2.jar;D:\Maven_Repository\org\springframework\spring-context-support\5.3.8\spring-context-support-5.3.8.jar;D:\Maven_Repository\com\sun\mail\jakarta.mail\1.6.7\jakarta.mail-1.6.7.jar;D:\Maven_Repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;D:\Maven_Repository\com\alibaba\fastjson\1.2.76\fastjson-1.2.76.jar;D:\Maven_Repository\io\springfox\springfox-swagger2\2.9.2\springfox-swagger2-2.9.2.jar;D:\Maven_Repository\io\swagger\swagger-annotations\1.5.20\swagger-annotations-1.5.20.jar;D:\Maven_Repository\io\swagger\swagger-models\1.5.20\swagger-models-1.5.20.jar;D:\Maven_Repository\io\springfox\springfox-spi\2.9.2\springfox-spi-2.9.2.jar;D:\Maven_Repository\io\springfox\springfox-core\2.9.2\springfox-core-2.9.2.jar;D:\Maven_Repository\io\springfox\springfox-schema\2.9.2\springfox-schema-2.9.2.jar;D:\Maven_Repository\io\springfox\springfox-swagger-common\2.9.2\springfox-swagger-common-2.9.2.jar;D:\Maven_Repository\io\springfox\springfox-spring-web\2.9.2\springfox-spring-web-2.9.2.jar;D:\Maven_Repository\com\google\guava\guava\20.0\guava-20.0.jar;D:\Maven_Repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\Maven_Repository\org\springframework\plugin\spring-plugin-core\1.2.0.RELEASE\spring-plugin-core-1.2.0.RELEASE.jar;D:\Maven_Repository\org\springframework\plugin\spring-plugin-metadata\1.2.0.RELEASE\spring-plugin-metadata-1.2.0.RELEASE.jar;D:\Maven_Repository\org\mapstruct\mapstruct\1.2.0.Final\mapstruct-1.2.0.Final.jar;D:\Maven_Repository\com\github\xiaoymin\swagger-bootstrap-ui\1.9.6\swagger-bootstrap-ui-1.9.6.jar;D:\Maven_Repository\org\springframework\boot\spring-boot-configuration-processor\2.5.2\spring-boot-configuration-processor-2.5.2.jar;D:\Maven_Repository\org\projectlombok\lombok\1.18.20\lombok-1.18.20.jar;D:\Maven_Repository\net\bytebuddy\byte-buddy\1.10.22\byte-buddy-1.10.22.jar;D:\Maven_Repository\org\springframework\spring-core\5.3.8\spring-core-5.3.8.jar;D:\Maven_Repository\org\springframework\spring-jcl\5.3.8\spring-jcl-5.3.8.jar;D:\Program Files\JetBrains\IntelliJ IDEA 2019.2.4\lib\idea_rt.jar" com.bowu66.spider.SpiderManApplication
Connected to the target VM, address: '127.0.0.1:59760', transport: 'socket'
. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )__ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' || .__|| ||| |_, | / / / /
=========||==============|/=////
:: Spring Boot :: (v2.5.2)
2021-12-08 20:55:05.048 INFO 74844 --- [ main] com.bowu66.spider.SpiderManApplication : Starting SpiderManApplication using Java 9 on lenovo-legion with PID 74844 (D:\IdeaProjects\spider-man\target\classes started by legion in D:\IdeaProjects\spider-man)
2021-12-08 20:55:05.050 INFO 74844 --- [ main] com.bowu66.spider.SpiderManApplication : No active profile set, falling back to default profiles: default
2021-12-08 20:55:05.762 INFO 74844 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-12-08 20:55:05.768 INFO 74844 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-12-08 20:55:05.769 INFO 74844 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-12-08 20:55:05.829 INFO 74844 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-12-08 20:55:05.829 INFO 74844 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 747 ms
2021-12-08 20:55:06.061 INFO 74844 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
( / )( _ ( _ )/ )
\ / )() ))()(( (
() (____/(_)_)
v1.1.2
2021-12-08 20:55:06.211 WARN 74844 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controllerSwagger' defined in class path resource [com/github/ydoc/config/AutoConfig.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException
2021-12-08 20:55:06.214 INFO 74844 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-12-08 20:55:06.220 INFO 74844 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-08 20:55:06.233 ERROR 74844 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controllerSwagger' defined in class path resource [com/github/ydoc/config/AutoConfig.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.8.jar:5.3.8]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.8.jar:5.3.8]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.2.jar:2.5.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.2.jar:2.5.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.2.jar:2.5.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.2.jar:2.5.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.2.jar:2.5.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.2.jar:2.5.2]
at com.bowu66.spider.SpiderManApplication.main(SpiderManApplication.java:12) [classes/:na]
Caused by: java.lang.NullPointerException: null
at java.base/java.util.ArrayList.addAll(ArrayList.java:598) ~[na:na]
at com.github.ydoc.core.RequestTypeMatchingSwagger.setHeaders(RequestTypeMatchingSwagger.java:26) ~[ydoc-spring-boot-starter-1.1.2.jar:1.1.2]
at com.github.ydoc.core.ScanControllerSwagger.scan(ScanControllerSwagger.java:83) ~[ydoc-spring-boot-starter-1.1.2.jar:1.1.2]
at com.github.ydoc.core.ScanControllerSwagger.afterPropertiesSet(ScanControllerSwagger.java:141) ~[ydoc-spring-boot-starter-1.1.2.jar:1.1.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.8.jar:5.3.8]
... 16 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:59760', transport: 'socket'
Process finished with exit code 1
已解决
当对像当中嵌套A对像,A对像在嵌套List实体,启动就会报错。经排查,这类RequestTypeMatchingSwagger,388行,//对象 先解析desc
Class declaringClass = declaredField.getClass();改成Class declaringClass = declaredField.getType();就可以了。感谢作者提供了这么方便的工具,省着自己录了。感谢
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.