Sonar Complains about Spring Boot Configuration

I have this class to start spring -cloud configuration server. This is spring-boot app.

@SpringBootApplication @EnableConfigServer @EnableDiscoveryClient public class ConfigServerApplication { public static void main( String[] args ) { SpringApplication.run( ConfigServerApplication.class, args ); } } 

The application works fine, and all my unit tests are fine. However, in our bamboo pipeline, he will begin the sonar process for code analysis. We continue to receive these minor warnings indicating the following:

 Utility classes should not have a public constructor 

I know this is a small problem, but I was instructed to remove them from our code.

Ideally, you would mark the final class and provide a private constructor, or therefore all search queries as a solution. However, the Spring Configuration class cannot be final and cannot have a private constructor.

Any ideas how to solve this problem?

+6
source share
3 answers

I am afraid this is not a spring-boot problem or spring-cloud might solve. You need to add exceptions to your sonar configuration.

+5
source

Easy to check:

 @RunWith(SpringRunner.class) @SpringBootTest public class YourApplicationTest { @Test public void shouldLoadApplicationContext() { } @Test public void applicationTest() { YourApplication.main(new String[] {}); } } 

Now Sonar says: this is verified!
(Kudos exits: Robert @ fooobar.com/questions/279358 / ... )

0
source

Tuning sonar parameters would, of course, be more enjoyable, but if you want to cater to machine spirits , you can simply add non-static dummy functions to your class, making it "unusable" in the eyes of a sonar test.

-1
source

All Articles