Bird
Raised Fist0
Spring Bootframework~10 mins

How auto-configuration works in Spring Boot - Interactive Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable Spring Boot auto-configuration in the main application class.

Spring Boot
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.[1](Application.class, args);
    }
}
Drag options to blanks, or click blank then click option'
Alaunch
Bstart
Cexecute
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name other than 'run' causes the app not to start.
Forgetting to call any method to launch the app.
2fill in blank
medium

Complete the annotation to enable Spring Boot's auto-configuration feature.

Spring Boot
@[1]
public class Application {}
Drag options to blanks, or click blank then click option'
AEnableAutoConfiguration
BSpringBootApplication
CAutoConfigure
DConfiguration
Attempts:
3 left
💡 Hint
Common Mistakes
Using only @EnableAutoConfiguration misses component scanning.
Using @Configuration alone does not enable auto-configuration.
3fill in blank
hard

Fix the error in the code to correctly exclude a specific auto-configuration class.

Spring Boot
@SpringBootApplication(exclude = [1].class)
public class Application {}
Drag options to blanks, or click blank then click option'
ADataSourceAutoConfiguration
BEnableAutoConfiguration
CSpringBootApplication
DAutoConfigure
Attempts:
3 left
💡 Hint
Common Mistakes
Using annotation names instead of class names causes errors.
Misspelling the class name.
4fill in blank
hard

Fill both blanks to create a conditional auto-configuration class that activates only if a bean is missing.

Spring Boot
@Configuration
@ConditionalOnMissingBean([1].class)
public class [2]AutoConfiguration {}
Drag options to blanks, or click blank then click option'
ADataSource
BJdbcTemplate
CCache
DSecurity
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated bean types causes the condition to fail.
Mismatching class names and bean types.
5fill in blank
hard

Fill all three blanks to define a custom auto-configuration class with proper annotations and bean method.

Spring Boot
@Configuration
@ConditionalOnClass([1].class)
public class [2]AutoConfiguration {
    @Bean
    public [1] [3]() {
        return new [1]();
    }
}
Drag options to blanks, or click blank then click option'
ARestTemplate
BMyService
CrestTemplate
DmyService
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for class and bean method.
Missing @Bean annotation.

Practice

(1/5)
1. What is the main purpose of Spring Boot's auto-configuration feature?
easy
A. To disable all default Spring features
B. To require manual configuration of all beans and settings
C. To force the use of XML configuration files
D. To automatically set up common configurations based on project dependencies

Solution

  1. Step 1: Understand auto-configuration role

    Auto-configuration helps by setting up default configurations automatically when certain dependencies are present.
  2. Step 2: Compare options

    Options A, B, and D contradict the purpose of auto-configuration, which is to reduce manual setup, not increase it or disable features.
  3. Final Answer:

    To automatically set up common configurations based on project dependencies -> Option D
  4. Quick Check:

    Auto-configuration = automatic setup [OK]
Hint: Auto-configuration means less manual setup [OK]
Common Mistakes:
  • Thinking auto-configuration disables features
  • Assuming all configuration must be manual
  • Confusing auto-configuration with XML config
2. Which annotation enables Spring Boot's auto-configuration in a main application class?
easy
A. @SpringBootApplication
B. @EnableAutoConfig
C. @AutoConfigEnabled
D. @ConfigurationAuto

Solution

  1. Step 1: Identify the correct annotation

    @SpringBootApplication is a meta-annotation that includes @EnableAutoConfiguration, enabling auto-configuration.
  2. Step 2: Verify other options

    Options B, C, and D are not valid Spring Boot annotations and will cause errors.
  3. Final Answer:

    @SpringBootApplication -> Option A
  4. Quick Check:

    @SpringBootApplication enables auto-config [OK]
Hint: Use @SpringBootApplication for auto-config [OK]
Common Mistakes:
  • Using non-existent annotations
  • Forgetting @SpringBootApplication on main class
  • Confusing with @Configuration only
3. Given this Spring Boot application snippet, what will happen if spring-boot-starter-web is on the classpath?
@SpringBootApplication
public class DemoApplication {
  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}
medium
A. Spring Boot auto-configures a web server and MVC setup
B. No web server is configured automatically
C. Application fails to start due to missing annotations
D. Only a command-line runner is configured

Solution

  1. Step 1: Check classpath dependency effect

    Presence of spring-boot-starter-web triggers auto-configuration of embedded web server and MVC components.
  2. Step 2: Analyze application code

    The main class is annotated with @SpringBootApplication, enabling auto-configuration which activates for web components due to the starter-web dependency.
  3. Final Answer:

    Spring Boot auto-configures a web server and MVC setup -> Option A
  4. Quick Check:

    Web starter on classpath = web auto-config [OK]
Hint: Web starter triggers web server auto-config [OK]
Common Mistakes:
  • Ignoring the effect of dependencies on auto-config
  • Assuming no server without explicit config
  • Forgetting @SpringBootApplication annotation
4. What is the likely cause of this error in a Spring Boot app?
@SpringBootApplication
public class App {
  public static void main(String[] args) {
    SpringApplication.run(App.class, args);
  }
}

// Error: No qualifying bean of type 'DataSource' available
medium
A. Incorrect main method signature
B. Auto-configuration is disabled by default
C. Missing database driver dependency causing auto-config to fail
D. Spring Boot does not support DataSource auto-configuration

Solution

  1. Step 1: Understand DataSource error

    Spring Boot tries to auto-configure a DataSource but fails if no driver dependency is found.
  2. Step 2: Check other options

    Main method is correct, auto-configuration is enabled by default, and Spring Boot supports DataSource auto-config.
  3. Final Answer:

    Missing database driver dependency causing auto-config to fail -> Option C
  4. Quick Check:

    Missing driver = DataSource bean error [OK]
Hint: Add DB driver to fix DataSource bean error [OK]
Common Mistakes:
  • Assuming main method is wrong
  • Thinking auto-config is off by default
  • Believing Spring Boot lacks DataSource support
5. You want to disable Spring Boot's auto-configuration for JPA but keep others enabled. Which is the correct way to do this?
hard
A. Remove all dependencies except JPA starter
B. Add @SpringBootApplication(exclude = JpaAutoConfiguration.class) on main class
C. Set spring.autoconfigure.enabled=false in application.properties
D. Delete the spring.factories file from the jar

Solution

  1. Step 1: Identify how to exclude specific auto-config

    Spring Boot allows excluding specific auto-config classes using the exclude attribute on @SpringBootApplication.
  2. Step 2: Evaluate other options

    Removing dependencies disables features but is not selective; disabling all auto-config is too broad; deleting spring.factories breaks the framework.
  3. Final Answer:

    Add @SpringBootApplication(exclude = JpaAutoConfiguration.class) on main class -> Option B
  4. Quick Check:

    Exclude specific auto-config via annotation [OK]
Hint: Use exclude attribute on @SpringBootApplication [OK]
Common Mistakes:
  • Disabling all auto-config instead of one
  • Removing dependencies instead of excluding config
  • Modifying internal Spring Boot files
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard