Search code examples
springspring-bootsonarqubespring-cloudspring-java-config

Sonar complains about Spring Boot configuration


I have this class to start up the spring-cloud config server. It is a spring-boot application.

@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public class ConfigServerApplication {

    public static void main( String[] args ) {

        SpringApplication.run( ConfigServerApplication.class, args );

    }

}

The application runs fine and all my unit tests are fine. However, in our bamboo pipeline, it will initial a sonar process to analyze the code. We keep getting these minor warnings indicating the following:

Utility classes should not have a public constructor

I know that this is a minor issue, but I have been tasked with removing these from our code.

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

Any ideas how to resolve this?


Solution

  • I'm afraid this isn't a problem spring-boot or spring-cloud can solve. You need to add exceptions to your sonar configuration.