java - Spring Boot 项目中的 SonarQube "Close this ConfigurableApplicationContext"

标签 java spring spring-boot sonarqube

我在主方法中遇到了阻塞问题“关闭此“ConfigurableApplicationContext””

public static void main(String[] args)
{
    SpringApplication.run(MyApplication.class, args);
}

我已经尝试过 SonarQube 示例中的代码

public static void main(String[] args)
{
    ConfigurableApplicationContext context = null;
    try
    {
        context = SpringApplication.run(MyApplication.class, args);
    }
    finally
    {
        if (context != null) {
            context.close();
        }
    }
}

但它会在启动后立即关闭上下文。

如何解决这个问题?

最佳答案

SonarQube 报告的问题是误报,应该被忽略。 SonarQube's FAQ列出了一些消除误报的选项:

False-Positive and Won't Fix

You can mark individual issues as False Positive or Won't Fix through the issues interface. However, this solution doesn't work across branches - you'll have to re-mark the issue False Positive for each branch under analysis. So an in-code approach may be preferable if multiple branches of a project are under analysis:

//NOSONAR

You can use the mechanism embedded in rules engine (//NOPMD...) or the generic mechanism implemented in SonarQube: put //NOSONAR at the end of the line of the issue. This will suppress the issue.

Switch Off Issues

You can review an issue to flag it as false positive directly from the user interface.

关于java - Spring Boot 项目中的 SonarQube "Close this ConfigurableApplicationContext",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37071032/

相关文章:

java - 为什么 -Xss 不增加创建的线程数?

java - 将原型(prototype)注入(inject)单例(java配置+注释)

java - @Transactional 使 getClass 在类上返回 com.sun.proxy.$Proxy

java - 我的 JDBC 有问题,但我不知道为什么

java - JVM G1 GC日志分析

java - Eclipse 不打开框架窗口

java - 当我使用 @JsonView 时,为什么 @InjectMocks Controller 的响应会被 Mockito 变成空?

java - Spring AOP : Trying to use for logging but getting IllegalArgumentException

java - 默认bean作用域为单例,并发调用时不是很糟糕吗?

java - 如何推迟Spring应用程序在Eureka中的注册,直到应用程序完全初始化?