Bird
0
0

You want to run a Spring Boot app and pass a custom argument 'user=admin' to the main method. How can you access this argument inside your application?

hard📝 Application Q9 of 15
Spring Boot - Fundamentals
You want to run a Spring Boot app and pass a custom argument 'user=admin' to the main method. How can you access this argument inside your application?
AUse System.getProperty('user')
BUse @Value annotation with '${user}' in any bean
CUse args parameter in main method and parse it manually
DUse @Autowired Environment and call getProperty('user')
Step-by-Step Solution
Solution:
  1. Step 1: Understand how command line args are passed

    Arguments passed to main are available in the args array and must be parsed manually.
  2. Step 2: Differentiate property injection vs args

    @Value and Environment get properties from Spring context, not direct main args unless passed as properties.
  3. Final Answer:

    Use args parameter in main method and parse it manually -> Option C
  4. Quick Check:

    Access main args directly via args array [OK]
Quick Trick: Parse main method args array to get custom arguments [OK]
Common Mistakes:
  • Assuming @Value reads main args
  • Using System.getProperty for args
  • Confusing environment properties with args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes