gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 13:50:06 27 4
gpt4 key购买 nike

我在主方法中遇到了阻塞问题“关闭此“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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com