Spring Boot Invalid Setup

ID

java.spring_boot_invalid_setup

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

best-practice, spring

Description

Reports @SpringBootApplication classes that reside in the default (unnamed) package, or that redundantly declare @EnableAutoConfiguration or @ComponentScan. The @SpringBootApplication meta-annotation already includes both, so repeating them is confusing and may override defaults unexpectedly.

Rationale

Reliability — Placing the bootstrap class in the default package causes Spring to scan the entire classpath. Redundant annotations may cause conflicting configuration and confuse maintainers.

Remediation

Non-compliant code

@SpringBootApplication
@EnableAutoConfiguration // redundant
public class MyApp { }

Compliant code

@SpringBootApplication
public class MyApp { }