What is the main class annotation to start a Spring Boot application?
The main class should be annotated with <code>@SpringBootApplication</code>. This annotation enables auto-configuration, component scanning, and configuration support.
Click to reveal answer
beginner
How do you run a Spring Boot application from the command line using Maven?
Use the command mvn spring-boot:run in the project directory. This compiles and runs the application without needing to build a jar first.
Click to reveal answer
beginner
What method is used to launch the Spring Boot application in the main class?
The method SpringApplication.run(MainClass.class, args) is called inside the main method to start the application.
Click to reveal answer
beginner
What file is commonly used to configure Spring Boot application properties?
The application.properties or application.yml file in the src/main/resources folder is used to configure settings like server port, database, and logging.
Click to reveal answer
intermediate
How can you package a Spring Boot application to run it as a standalone jar?
Use mvn clean package to build a jar file in the target folder. Run it with java -jar target/appname.jar to start the app.
Click to reveal answer
Which annotation marks the main class to enable Spring Boot features?
A@SpringBootApplication
B@EnableAutoConfiguration
C@ComponentScan
D@Configuration
✗ Incorrect
The @SpringBootApplication annotation combines @EnableAutoConfiguration, @ComponentScan, and @Configuration for convenience.
What command runs a Spring Boot app using Maven without building a jar?
Amvn package
Bmvn clean install
Cjava -jar app.jar
Dmvn spring-boot:run
✗ Incorrect
The mvn spring-boot:run command compiles and runs the app directly.
Where do you place application configuration files in a Spring Boot project?
Asrc/main/java
Bsrc/test/resources
Csrc/main/resources
Dsrc/config
✗ Incorrect
Configuration files like application.properties go in src/main/resources.
Which method starts the Spring Boot application inside the main class?
AApplication.start()
BSpringApplication.run()
CBoot.run()
DMain.launch()
✗ Incorrect
SpringApplication.run() launches the Spring Boot app.
How do you run a packaged Spring Boot jar file?
Ajava -jar target/appname.jar
Bmvn spring-boot:run
Cjava appname.jar
Dmvn run
✗ Incorrect
Use java -jar followed by the jar file path to run the packaged app.
Explain the steps to run a Spring Boot application from source code using Maven.
Think about the main class setup and the Maven command to start the app.
You got /3 concepts.
Describe how to package and run a Spring Boot application as a standalone jar.
Focus on building and running the jar file.
You got /3 concepts.
Practice
(1/5)
1. What is the main method used for in a Spring Boot application?
easy
A. To configure the database connection
B. To start the Spring Boot application using SpringApplication.run()
C. To define REST endpoints
D. To create HTML views
Solution
Step 1: Understand the role of the main method
The main method is the entry point of any Java application, including Spring Boot apps.
Step 2: Identify what SpringApplication.run() does
SpringApplication.run() starts the Spring Boot application by initializing the Spring context and components.
Final Answer:
To start the Spring Boot application using SpringApplication.run() -> Option B
Quick Check:
Main method starts app = To start the Spring Boot application using SpringApplication.run() [OK]
Hint: Main method always starts Spring Boot with SpringApplication.run() [OK]
Common Mistakes:
Confusing main method with configuration tasks
Thinking main method defines endpoints
Assuming main method creates UI views
2. Which of the following is the correct way to run a Spring Boot application from the command line using Maven?
easy
A. mvn spring-boot:run
B. mvn run spring-boot
C. mvn start boot
D. mvn execute springboot
Solution
Step 1: Recall Maven command for Spring Boot
The standard Maven command to run a Spring Boot app is 'mvn spring-boot:run'.
Step 2: Check other options for correctness
Other options do not follow Maven or Spring Boot plugin syntax and will cause errors.
Final Answer:
mvn spring-boot:run -> Option A
Quick Check:
Maven run command = mvn spring-boot:run [OK]
Hint: Use 'mvn spring-boot:run' to run Spring Boot apps with Maven [OK]
Common Mistakes:
Mixing up command order
Using invalid Maven goals
Typing incomplete commands
3. Given this main class, what happens when you run it?
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
medium
A. The application starts and initializes Spring Boot context
B. The application throws a compilation error
C. The application runs but does not start Spring Boot
D. The application starts but immediately exits without running
Solution
Step 1: Analyze the main method code
The main method calls SpringApplication.run() with the class annotated by @SpringBootApplication.
Step 2: Understand @SpringBootApplication effect
This annotation enables auto-configuration and component scanning, so Spring Boot context starts properly.
Final Answer:
The application starts and initializes Spring Boot context -> Option A
Quick Check:
SpringApplication.run() starts app = The application starts and initializes Spring Boot context [OK]
Hint: SpringApplication.run() with @SpringBootApplication starts app [OK]
Common Mistakes:
Thinking @SpringBootApplication is optional
Assuming code throws error without extra config
Believing app runs but does not start Spring context
4. You try to run your Spring Boot app but get this error: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication. What is the most likely cause?
medium
A. The Java version is too new for Spring Boot
B. The main method is missing in the application class
C. The Spring Boot dependency is missing from the project
D. The application.properties file is empty
Solution
Step 1: Understand the error meaning
NoClassDefFoundError means the JVM cannot find the SpringApplication class at runtime.
Step 2: Identify cause of missing class
This usually happens if the Spring Boot dependency is not included or not properly loaded in the project.
Final Answer:
The Spring Boot dependency is missing from the project -> Option C
Quick Check:
NoClassDefFoundError = missing dependency [OK]
Hint: NoClassDefFoundError usually means missing dependency [OK]
Common Mistakes:
Blaming missing main method for this error
Thinking empty config files cause class errors
Assuming Java version causes missing class
5. You want to run your Spring Boot app as a standalone jar. Which command correctly runs the jar file named app.jar?
medium
A. mvn run app.jar
B. java run app.jar
C. gradle run app.jar
D. java -jar app.jar
Solution
Step 1: Recall how to run a jar file in Java
The standard command to run an executable jar is 'java -jar filename.jar'.
Step 2: Check other options for correctness
The mvn and gradle commands are for build tools, not for running jar files directly. 'java run app.jar' is invalid Java command syntax.
Final Answer:
java -jar app.jar -> Option D
Quick Check:
Run jar with 'java -jar' = java -jar app.jar [OK]
Hint: Run jar files with 'java -jar filename.jar' [OK]
Common Mistakes:
Using build tool commands to run jar directly
Omitting '-jar' option
Typing invalid Java commands
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.