// Avoid: A → B → A constructor injection (fails by default in Boot 2.6+)// Fix 1: Refactor — extract shared logic into 3rd bean// Fix 2: Use setter injection on one side// Fix 3: @Lazy on the back-edge dependencypublic A(@Lazy B b) { this.b = b; }
Warning:spring.main.allow-circular-references=true "fixes" the
symptom but masks design problems.
3. Debugging Auto-Configuration Problems
Tool
Use
--debug flag
Print auto-config report
/actuator/conditions
Matched / unmatched conditions
@SpringBootApplication(exclude = {X.class})
Disable specific autoconfig
spring.autoconfigure.exclude
Property-based exclusion
4. Resolving Port Already in Use (server.port)
Example: Find port conflict and use random port
# Find process holding the portlsof -i :8080# Or use random portSERVER_PORT=0 java -jar app.jar# Or assign dynamicallyserver.port=0 # in application.yml
5. Fixing ClassNotFoundException and NoClassDefFoundError
Cause
Fix
Missing dependency
Add to pom/gradle
Version conflict
mvn dependency:tree + exclusions
Provided/test scope only
Change to compile/runtime
Static initializer failed (NoClassDefFoundError after first OK)