huaweicloud / spring-cloud-huawei

Spring Cloud Huawei is a framework that makes it easier and productive to develop microservices with Spring Cloud.
https://github.com/huaweicloud/spring-cloud-huawei/wiki
Apache License 2.0
520 stars 223 forks source link

Swagger扫描到带有@Scope('request')的RestController报错 #1287

Open luyiwei111 opened 5 months ago

luyiwei111 commented 5 months ago

Swagger扫描到带有@Scope('request')的RestController报错

Spring Cloud Huawei version: 1.11.7-2021.-.x

具体报错见附件 :swagger报错.txt

现本地修改源码仅供参考,解决了问题,建议是否可以参考 我修改的代码来屏蔽此类带有@Scpoe('request')的@RestController

    private void runJavaChassisScanner() {
        Map<String, Object> controllers = new HashMap<>();
        //修改原先的  Map<String, Object> controllers = applicationContext.getBeansWithAnnotation(RestController.class);
       //先找到beanname,然后用try catch过滤掉无法生成的bean
        final String[] beanNamesForAnnotation = applicationContext.getBeanNamesForAnnotation(RestController.class);
        for (String beanName : beanNamesForAnnotation) {
            try {
                Object beanInstance = applicationContext.getBean(beanName);
                controllers.put(beanName, beanInstance);
            }
            catch (ScopeNotActiveException e) {
                LOGGER.warn("bean [{}] is not active in current scope, ignore it.", beanName);
            }
        }
        controllers.forEach((k, v) -> {
            try {
                SpringmvcSwaggerGenerator generator = new SpringmvcSwaggerGenerator(v.getClass());
                Swagger swagger = generator.generate();
                swaggerContent.put(k, SwaggerUtils.swaggerToString(swagger));
                LOGGER.info("generate servicecomb compatible swagger for bean [{}] success.", k);
            }
            catch (Exception e) {
                LOGGER.info("generate servicecomb compatible swagger for bean [{}] failed, message is [{}].", k,
                        e.getMessage());
            }
        });
        swaggerSummary = calcSchemaSummary();
    }
luyiwei111 commented 5 months ago

另外麻烦同步看下#1288

chengyouling commented 4 months ago

see https://github.com/huaweicloud/spring-cloud-huawei/pull/1297