Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
luyiwei111 opened this issue Jun 27, 2024 · 2 comments
Open

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

luyiwei111 opened this issue Jun 27, 2024 · 2 comments

Comments

@luyiwei111
Copy link

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
Copy link
Author

另外麻烦同步看下#1288

@chengyouling
Copy link
Collaborator

see #1297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants