Bird
0
0

In a multi-module Spring Boot project, you want to share common utility classes across modules without duplicating code. Which approach is best?

hard📝 Application Q15 of 15
Spring Boot - Advanced Patterns
In a multi-module Spring Boot project, you want to share common utility classes across modules without duplicating code. Which approach is best?
ACopy utility classes into each module's source folder
BCreate a separate <code>common</code> module and add it as a dependency to other modules
CPut all utility classes in the parent <code>pom.xml</code>
DUse <code>application.properties</code> to share utility classes
Step-by-Step Solution
Solution:
  1. Step 1: Identify code sharing strategy

    To avoid duplication, create a dedicated common module for shared utilities.
  2. Step 2: Use module dependencies

    Other modules add common as a dependency to access shared code cleanly.
  3. Final Answer:

    Create a separate common module and add it as a dependency to other modules -> Option B
  4. Quick Check:

    Shared code in common module [OK]
Quick Trick: Use a common module for shared code [OK]
Common Mistakes:
  • Copying code causes duplication and maintenance issues
  • Trying to put code in pom.xml (not for code)
  • Using properties files to share classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes