What is the significance of @MockBean in Spring tests?
@MockBean puts a Mockito mock into the Spring test context so beans receive a controllable fake. Learn how to use it and migrate to @MockitoBean.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
@MockBean puts a Mockito mock into the Spring test context so beans receive a controllable fake. Learn how to use it and migrate to @MockitoBean.
Create mocks with @Mock, inject them with @InjectMocks, stub calls and verify interactions. A complete JUnit 5 example with Mockito 5 and best practices.
TestRestTemplate calls your running Spring Boot endpoints over HTTP in tests. See setup, POST and auth examples and how it compares with MockMvc.
Use @SpringBootTest, test slices and Testcontainers to verify that your Spring Boot beans, database and web layer work together as in production.
MockMvc tests Spring MVC controllers in memory, checking mappings, validation, JSON and security without a server. See setups and examples.
Use @WebMvcTest, MockMvc and @MockitoBean to test Spring MVC controllers: requests, JSON assertions, validation, exception handling and secured endpoints.
Flyway is SQL-first and simple; Liquibase is declarative with richer rollback and portability. See how they compare and which one fits your project.
Flyway and Liquibase record every applied schema change in a history table. Learn how to set up either one in Spring Boot and keep migrations safe.
Liquibase applies versioned database changes automatically when a Spring Boot application starts. See how to configure changelogs, contexts and rollbacks.
Set up Flyway database migrations in Spring Boot with dependencies, naming rules, properties, baselining and safe production practices.
Flyway applies versioned SQL migrations once and in order, so every environment has the same schema. See setup, naming rules and safe practices in Spring Boot.
@ConfigurationProperties binds datasource and pool settings to beans, which makes multiple databases easy. Learn Hikari bindings, jdbc-url and @Primary.
Configure a HikariCP connection pool in a plain Spring application, wire it into JdbcTemplate and transactions, and size and monitor it correctly.
The Java DataSource interface abstracts how JDBC connections are created, enabling pooling, JNDI lookup and XA transactions, and replacing DriverManager in real applications.
Set spring.datasource properties, tune HikariCP, define DataSource beans in Java and configure multiple databases in a Spring Boot application.
PlatformTransactionManager is Spring's core transaction abstraction. It starts, commits and rolls back transactions for JDBC, JPA or JTA, behind @Transactional and TransactionTemplate.
Annotate service methods with @Transactional and Spring begins, commits and rolls back for you. Learn the attributes, rollback defaults and common pitfalls.
@Transactional is Spring's declarative layer; JTA is the standard for distributed transactions. Learn how they relate and when you really need JTA.
Run Spring event listeners off the publisher thread with @Async and @EventListener, and learn executors, exceptions, and transaction timing.
@EventListener turns a Spring bean method into an event handler, so components react to published events without implementing ApplicationListener.