Spring Professional Develop Free Sample Questions

Create a free account to browse all 20 sample questions. The full practice test includes 192 questions. Use the simulator for timed and flashcard mode.

Try Simulator

2V0-72-22 Sample Questions

  1. Question 1

    Q1

    A development team is building a library of custom Spring Boot auto-configurations. To ensure a custom configuration MyCustomAutoConfiguration is only activated when the ThirdPartyService.class is present on the classpath, and a bean of type DataSource has already been configured by another auto-configuration, which combination of annotations should be used on the configuration class?

    Show answer & explanation

    Correct answer: A

    The correct approach is to use @ConditionalOnClass(ThirdPartyService.class) to check for the presence of the class on the classpath, and @ConditionalOnBean(DataSource.class) to ensure a DataSource bean is already present in the context before this configuration is applied. @Configuration is necessary to mark the class as a source of bean definitions.

  2. Question 2

    Q2

    A developer is implementing an AOP aspect to log method executions. They notice that when a public method calls another public method within the same service bean, the advice is not triggered for the second, inner method call. What is the fundamental reason for this behavior in Spring's proxy-based AOP?

    Show answer & explanation

    Correct answer: A

    Spring AOP works by creating a proxy object that wraps the actual bean. External calls go through the proxy, allowing advices to be applied. However, an internal method call (this.innerMethod()) is a direct invocation on the target object itself, completely bypassing the proxy and any associated AOP logic. This is known as the self-invocation problem.

  3. Question 3

    Q3

    A financial application needs to perform a complex operation involving two separate database updates. The outer service method, transferFunds(), is annotated with @Transactional(propagation = Propagation.REQUIRED). It calls an inner service method, logAudit(), which must commit its record regardless of whether the transferFunds operation succeeds or fails. Which propagation level should be applied to the logAudit() method to achieve this behavior?

    Show answer & explanation

    Correct answer: B

    REQUIRES_NEW starts a new, independent transaction for the logAudit() method. The existing transaction (from transferFunds()) is suspended. This allows the inner transaction to commit on its own, ensuring the audit log is saved even if the outer transaction fails and rolls back.

  4. Question 4

    Q4Multiple answers

    A developer needs to configure a Spring Security setup for a REST API. The requirement is to allow unauthenticated access to /api/public/** endpoints, while all other endpoints under /api/** must be authenticated. Which two of the following HttpSecurity configurations correctly implement this requirement? (Select TWO)

    Show answer & explanation

    Correct answers: A, C

    This configuration correctly uses the principle of ordering matchers from most specific to most general. It first permits all access to /api/public/** and then requires authentication for all other /api/** paths.

    This is also a correct and common pattern. It permits access to the public endpoints and then uses anyRequest().authenticated() as a catch-all to secure everything else. Since /api/public/** is matched first, it works as required.

  5. Question 5

    Q5

    When writing a slice test for a Spring Data JPA repository using @DataJpaTest, the test transaction will, by default, roll back at the end of each test method.

    Show answer & explanation

    Correct answer: A

    The @DataJpaTest annotation is meta-annotated with @Transactional. In a test context, @Transactional ensures that each test method runs in a transaction that is rolled back by default upon completion. This keeps tests isolated and prevents them from polluting the database state for subsequent tests.

  6. Question 6

    Q6

    A Spring Boot application needs to connect to a database whose credentials are provided via environment variables DB_URL, DB_USER, and DB_PASS. The application.properties file contains the following entries:

    spring.datasource.url=${DB_URL:jdbc:h2:mem:defaultdb}
    spring.datasource.username=${DB_USER:sa}
    spring.datasource.password=${DB_PASS:}

    If the DB_USER environment variable is NOT set, but DB_URL and DB_PASS are, what value will be used for the datasource username?

    Show answer & explanation

    Correct answer: A

    The syntax ${PROPERTY:defaultValue} is used for property placeholders. If the PROPERTY (in this case, the DB_USER environment variable) is not found, the defaultValue (sa) will be used instead.

  7. Question 7

    Q7

    An architect is designing a REST API using Spring MVC. The API needs to return different JSON representations of a User object depending on the endpoint. For example, /api/users/{id} should return all user fields, but /api/users/summary should return only the id and username. What is the most appropriate Spring feature to implement this requirement without creating separate DTOs (Data Transfer Objects) for each view?

    Show answer & explanation

    Correct answer: A

    Jackson's @JsonView annotation, which is well-integrated with Spring MVC, is designed for this exact purpose. It allows you to define multiple 'views' (e.g., public, internal) on a single model object and then specify which view to use for serialization at the controller method level, enabling different JSON outputs from the same object.

  8. Question 8

    Q8

    A developer needs to create a Spring bean that calculates a value based on other beans, but this calculation only needs to happen once at startup. The result should then be cached and injected into other components. Which combination of annotations and lifecycle callbacks is most suitable for this scenario?

    Show answer & explanation

    Correct answer: A

    This is the ideal approach. A singleton bean is created only once. Injecting dependencies via the constructor ensures they are available when the bean is initialized. The @PostConstruct annotation guarantees the calculation method runs after dependency injection is complete but before the bean is made available to other components. The result can be stored in a field for subsequent use.

  9. Question 9

    Q9

    A Spring Boot application uses a JdbcTemplate to perform database queries. During a code review, a senior developer points out a potential SQL injection vulnerability in the following code snippet:

    String status = "ACTIVE";
    String sql = "SELECT * FROM users WHERE status = '" + status + "'";
    jdbcTemplate.query(sql, userRowMapper);

    What is the best way to refactor this code to prevent the SQL injection vulnerability?

    Show answer & explanation

    Correct answer: A

    The correct and standard way to prevent SQL injection is to use parameterized queries (prepared statements). The JdbcTemplate supports this by using ? as a placeholder in the SQL string and passing the actual values as separate arguments to the query method. This ensures user input is treated as data, not executable code. The refactored code would be: String sql = "SELECT * FROM users WHERE status = ?"; jdbcTemplate.query(sql, new Object[]{status}, userRowMapper);

  10. Question 10

    Q10

    Company Background
    A large e-commerce company, "ShopFast", is modernizing its monolithic backend. They are adopting a microservices architecture and have chosen Spring Boot for new services. One of the first services being built is the OrderProcessingService. This service needs to be highly available and observable.

    Current Situation
    The development team has built the core logic for the OrderProcessingService. It exposes several REST endpoints for creating and querying orders. The service interacts with a PostgreSQL database and a RabbitMQ message queue. The company has a centralized Prometheus server for metrics collection and Grafana for dashboarding. The security team mandates that all management endpoints must be secured and only accessible by administrators.

    Requirements

    1. The service must expose its operational status, including database connectivity and message queue health.
    2. Key business metrics, such as orders_created and order_processing_time, must be exposed in a format compatible with Prometheus.
    3. All management and monitoring endpoints must be exposed on a separate port from the main application port (8080) for security reasons.
    4. Access to these management endpoints must be restricted to users with the ADMIN role.

    Question
    Which set of configurations in application.properties and dependencies in pom.xml will satisfy all the stated requirements?

    Show answer & explanation

    Correct answer: A

    This solution correctly addresses all requirements. spring-boot-starter-actuator provides the health and metrics endpoints. micrometer-registry-prometheus ensures metrics are in the Prometheus format. management.server.port=9090 isolates the management endpoints. management.endpoints.web.exposure.include=* exposes all endpoints, including the required health and prometheus ones. Finally, adding spring-boot-starter-security and configuring HttpSecurity allows for role-based access control to the actuator path, fulfilling the security requirement.

Register free to unlock 10 more sample questions

Create a free account to continue with the rest of the 2V0-72-22 sample set.

Lifetime One

Own this practice test forever.

$79.99
$75.99
one-time
  • Full access to 192 questions
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • Brainy AI Assistant
  • Lifetime updates

Two

Any 2 exams per month.

$20.00/exam
$39.99
/month
  • 2 active exam slots
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • 1,000 Brainy AI Credits
  • Cancel anytime

Premium Twelve

Any 12 exams over 3 months.

$15.00/exam
$179.99
/3 months
  • 4 active exam slots
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • 15,000 Brainy AI Credits
  • Dedicated support
  • Friend seat included — full access

Trusted by professionals at

NvidiaSupabaseGitHubOpenAITursoClerkClaude AIAmazon