[{"data":1,"prerenderedAt":2102},["ShallowReactive",2],{"page-en-\u002Fblog\u002Fspring-boot-testcontainers":3,"related-en-\u002Fblog\u002Fspring-boot-testcontainers":2081},{"id":4,"title":5,"body":6,"date":2067,"description":2068,"extension":2069,"meta":2070,"navigation":458,"path":2071,"seo":2072,"stem":2073,"tags":2074,"translation":2079,"__hash__":2080},"pages_en\u002Fen\u002Fblog\u002Fspring-boot-testcontainers.md","Testing Spring Boot and JPA with Testcontainers",{"type":7,"value":8,"toc":2052},"minimark",[9,14,18,30,34,132,135,139,375,398,401,405,411,525,535,538,542,791,808,812,817,1109,1114,1118,1129,1162,1177,1181,1184,1198,1478,1489,1493,1496,1510,1516,1546,1565,1568,1572,1578,1770,1776,1780,1790,1898,1913,1917,1924,2008,2011,2038,2042,2048],[10,11,13],"h2",{"id":12},"introduction","Introduction",[15,16,17],"p",{},"For many years, the default choice for testing JPA\u002FHibernate code was an in-memory database like H2: fast, no setup needed. But queries that pass on H2 and blow up on PostgreSQL in production are the price of that convenience.",[15,19,20,24,25,29],{},[21,22,23],"strong",{},"Testcontainers"," starts a real database (or Redis, Kafka, RabbitMQ...) on Docker during tests and removes it when they finish. Combined with Spring Boot's ",[26,27,28],"code",{},"@ServiceConnection"," support, setup comes down to a few lines. This post shows how to test the examples from the Hibernate and Spring Boot series against a real database.",[10,31,33],{"id":32},"_1-why-not-h2","1. Why not H2?",[35,36,37,53],"table",{},[38,39,40],"thead",{},[41,42,43,47,50],"tr",{},[44,45,46],"th",{},"Topic",[44,48,49],{},"H2",[44,51,52],{},"PostgreSQL",[54,55,56,68,86,97,110,121],"tbody",{},[41,57,58,62,65],{},[59,60,61],"td",{},"SQL dialect",[59,63,64],{},"Has a compatibility mode, but not identical",[59,66,67],{},"Same as production",[41,69,70,80,83],{},[59,71,72,75,76,79],{},[26,73,74],{},"jsonb",", array, ",[26,77,78],{},"uuid"," types",[59,81,82],{},"Limited or different behavior",[59,84,85],{},"Full support",[41,87,88,91,94],{},[59,89,90],{},"Native queries, window functions",[59,92,93],{},"Partial",[59,95,96],{},"Full",[41,98,99,105,108],{},[59,100,101,104],{},[26,102,103],{},"FOR UPDATE SKIP LOCKED",", lock behavior",[59,106,107],{},"Different",[59,109,67],{},[41,111,112,115,118],{},[59,113,114],{},"Migrations (Flyway)",[59,116,117],{},"May need separate scripts",[59,119,120],{},"Same scripts",[41,122,123,126,129],{},[59,124,125],{},"Index and constraint errors",[59,127,128],{},"Different messages\u002Fbehavior",[59,130,131],{},"Same",[15,133,134],{},"In short, H2 tests test a database you don't actually use. With Testcontainers, your tests run on the same PostgreSQL version as production.",[10,136,138],{"id":137},"_2-dependencies","2. Dependencies",[140,141,146],"pre",{"className":142,"code":143,"language":144,"meta":145,"style":145},"language-xml shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u003Cdependency>\n  \u003CgroupId>org.springframework.boot\u003C\u002FgroupId>\n  \u003CartifactId>spring-boot-testcontainers\u003C\u002FartifactId>\n  \u003Cscope>test\u003C\u002Fscope>\n\u003C\u002Fdependency>\n\u003Cdependency>\n  \u003CgroupId>org.testcontainers\u003C\u002FgroupId>\n  \u003CartifactId>testcontainers-postgresql\u003C\u002FartifactId>\n  \u003Cscope>test\u003C\u002Fscope>\n\u003C\u002Fdependency>\n\u003Cdependency>\n  \u003CgroupId>org.testcontainers\u003C\u002FgroupId>\n  \u003CartifactId>testcontainers-junit-jupiter\u003C\u002FartifactId>\n  \u003Cscope>test\u003C\u002Fscope>\n\u003C\u002Fdependency>\n","xml","",[26,147,148,164,187,206,225,234,243,261,279,296,305,314,331,349,366],{"__ignoreMap":145},[149,150,153,157,161],"span",{"class":151,"line":152},"line",1,[149,154,156],{"class":155},"sMK4o","\u003C",[149,158,160],{"class":159},"swJcz","dependency",[149,162,163],{"class":155},">\n",[149,165,167,170,173,176,180,183,185],{"class":151,"line":166},2,[149,168,169],{"class":155},"  \u003C",[149,171,172],{"class":159},"groupId",[149,174,175],{"class":155},">",[149,177,179],{"class":178},"sTEyZ","org.springframework.boot",[149,181,182],{"class":155},"\u003C\u002F",[149,184,172],{"class":159},[149,186,163],{"class":155},[149,188,190,192,195,197,200,202,204],{"class":151,"line":189},3,[149,191,169],{"class":155},[149,193,194],{"class":159},"artifactId",[149,196,175],{"class":155},[149,198,199],{"class":178},"spring-boot-testcontainers",[149,201,182],{"class":155},[149,203,194],{"class":159},[149,205,163],{"class":155},[149,207,209,211,214,216,219,221,223],{"class":151,"line":208},4,[149,210,169],{"class":155},[149,212,213],{"class":159},"scope",[149,215,175],{"class":155},[149,217,218],{"class":178},"test",[149,220,182],{"class":155},[149,222,213],{"class":159},[149,224,163],{"class":155},[149,226,228,230,232],{"class":151,"line":227},5,[149,229,182],{"class":155},[149,231,160],{"class":159},[149,233,163],{"class":155},[149,235,237,239,241],{"class":151,"line":236},6,[149,238,156],{"class":155},[149,240,160],{"class":159},[149,242,163],{"class":155},[149,244,246,248,250,252,255,257,259],{"class":151,"line":245},7,[149,247,169],{"class":155},[149,249,172],{"class":159},[149,251,175],{"class":155},[149,253,254],{"class":178},"org.testcontainers",[149,256,182],{"class":155},[149,258,172],{"class":159},[149,260,163],{"class":155},[149,262,264,266,268,270,273,275,277],{"class":151,"line":263},8,[149,265,169],{"class":155},[149,267,194],{"class":159},[149,269,175],{"class":155},[149,271,272],{"class":178},"testcontainers-postgresql",[149,274,182],{"class":155},[149,276,194],{"class":159},[149,278,163],{"class":155},[149,280,282,284,286,288,290,292,294],{"class":151,"line":281},9,[149,283,169],{"class":155},[149,285,213],{"class":159},[149,287,175],{"class":155},[149,289,218],{"class":178},[149,291,182],{"class":155},[149,293,213],{"class":159},[149,295,163],{"class":155},[149,297,299,301,303],{"class":151,"line":298},10,[149,300,182],{"class":155},[149,302,160],{"class":159},[149,304,163],{"class":155},[149,306,308,310,312],{"class":151,"line":307},11,[149,309,156],{"class":155},[149,311,160],{"class":159},[149,313,163],{"class":155},[149,315,317,319,321,323,325,327,329],{"class":151,"line":316},12,[149,318,169],{"class":155},[149,320,172],{"class":159},[149,322,175],{"class":155},[149,324,254],{"class":178},[149,326,182],{"class":155},[149,328,172],{"class":159},[149,330,163],{"class":155},[149,332,334,336,338,340,343,345,347],{"class":151,"line":333},13,[149,335,169],{"class":155},[149,337,194],{"class":159},[149,339,175],{"class":155},[149,341,342],{"class":178},"testcontainers-junit-jupiter",[149,344,182],{"class":155},[149,346,194],{"class":159},[149,348,163],{"class":155},[149,350,352,354,356,358,360,362,364],{"class":151,"line":351},14,[149,353,169],{"class":155},[149,355,213],{"class":159},[149,357,175],{"class":155},[149,359,218],{"class":178},[149,361,182],{"class":155},[149,363,213],{"class":159},[149,365,163],{"class":155},[149,367,369,371,373],{"class":151,"line":368},15,[149,370,182],{"class":155},[149,372,160],{"class":159},[149,374,163],{"class":155},[15,376,377,378,381,382,385,386,389,390,393,394,397],{},"Spring Boot's dependency management handles the versions; don't write them by hand. Note: with ",[21,379,380],{},"Testcontainers 2.x",", module artifacts were renamed to ",[26,383,384],{},"testcontainers-\u003Cmodule>"," and some classes moved packages (for example, ",[26,387,388],{},"PostgreSQLContainer"," now lives in ",[26,391,392],{},"org.testcontainers.postgresql","). In older projects on Testcontainers 1.x, the artifact name is ",[26,395,396],{},"postgresql",".",[15,399,400],{},"Docker (or a compatible runtime such as Podman) must be running on the machine.",[10,402,404],{"id":403},"_3-defining-the-container-as-a-bean","3. Defining the container as a bean",[15,406,407,408,410],{},"Since Spring Boot 3.1, the cleanest approach is to define the container as a bean in a test configuration and mark it with ",[26,409,28],{},":",[140,412,416],{"className":413,"code":414,"language":415,"meta":145,"style":145},"language-java shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","@TestConfiguration(proxyBeanMethods = false)\npublic class TestcontainersConfiguration {\n\n    @Bean\n    @ServiceConnection\n    PostgreSQLContainer postgres() {\n        return new PostgreSQLContainer(\"postgres:17-alpine\");\n    }\n}\n","java",[26,417,418,440,454,460,468,475,489,515,520],{"__ignoreMap":145},[149,419,420,423,427,430,434,437],{"class":151,"line":152},[149,421,422],{"class":155},"@",[149,424,426],{"class":425},"spNyl","TestConfiguration",[149,428,429],{"class":155},"(",[149,431,433],{"class":432},"sBMFI","proxyBeanMethods",[149,435,436],{"class":155}," =",[149,438,439],{"class":155}," false)\n",[149,441,442,445,448,451],{"class":151,"line":166},[149,443,444],{"class":425},"public",[149,446,447],{"class":425}," class",[149,449,450],{"class":432}," TestcontainersConfiguration",[149,452,453],{"class":155}," {\n",[149,455,456],{"class":151,"line":189},[149,457,459],{"emptyLinePlaceholder":458},true,"\n",[149,461,462,465],{"class":151,"line":208},[149,463,464],{"class":155},"    @",[149,466,467],{"class":425},"Bean\n",[149,469,470,472],{"class":151,"line":227},[149,471,464],{"class":155},[149,473,474],{"class":425},"ServiceConnection\n",[149,476,477,480,484,487],{"class":151,"line":236},[149,478,479],{"class":425},"    PostgreSQLContainer",[149,481,483],{"class":482},"s2Zo4"," postgres",[149,485,486],{"class":155},"()",[149,488,453],{"class":155},[149,490,491,495,498,501,503,506,510,512],{"class":151,"line":245},[149,492,494],{"class":493},"s7zQu","        return",[149,496,497],{"class":493}," new",[149,499,500],{"class":482}," PostgreSQLContainer",[149,502,429],{"class":155},[149,504,505],{"class":155},"\"",[149,507,509],{"class":508},"sfazB","postgres:17-alpine",[149,511,505],{"class":155},[149,513,514],{"class":155},");\n",[149,516,517],{"class":151,"line":263},[149,518,519],{"class":155},"    }\n",[149,521,522],{"class":151,"line":281},[149,523,524],{"class":155},"}\n",[15,526,527,528,530,531,534],{},"Thanks to ",[26,529,28],{},", ",[26,532,533],{},"spring.datasource.url",", the username and password are taken from the container automatically; you don't need to write any properties. The container starts with the Spring context and stops when the context closes.",[15,536,537],{},"Keep the image tag the same as your production PostgreSQL version.",[10,539,541],{"id":540},"_4-integration-test-with-springboottest","4. Integration test with @SpringBootTest",[140,543,545],{"className":413,"code":544,"language":415,"meta":145,"style":145},"@SpringBootTest\n@Import(TestcontainersConfiguration.class)\nclass OrderServiceIT {\n\n    @Autowired\n    OrderService orderService;\n\n    @Autowired\n    OrderRepository orderRepository;\n\n    @Test\n    void createsOrderWithItems() {\n        Long id = orderService.create(new CreateOrder(\"sukru\", List.of(\"book\", \"pen\")));\n\n        Order order = orderRepository.findWithItemsById(id).orElseThrow();\n        assertThat(order.getItems()).hasSize(2);\n    }\n}\n",[26,546,547,554,574,583,587,594,605,609,615,625,629,636,648,716,720,751,781,786],{"__ignoreMap":145},[149,548,549,551],{"class":151,"line":152},[149,550,422],{"class":155},[149,552,553],{"class":425},"SpringBootTest\n",[149,555,556,558,561,563,566,568,571],{"class":151,"line":166},[149,557,422],{"class":155},[149,559,560],{"class":425},"Import",[149,562,429],{"class":155},[149,564,565],{"class":178},"TestcontainersConfiguration",[149,567,397],{"class":155},[149,569,570],{"class":178},"class",[149,572,573],{"class":155},")\n",[149,575,576,578,581],{"class":151,"line":189},[149,577,570],{"class":425},[149,579,580],{"class":432}," OrderServiceIT",[149,582,453],{"class":155},[149,584,585],{"class":151,"line":208},[149,586,459],{"emptyLinePlaceholder":458},[149,588,589,591],{"class":151,"line":227},[149,590,464],{"class":155},[149,592,593],{"class":425},"Autowired\n",[149,595,596,599,602],{"class":151,"line":236},[149,597,598],{"class":425},"    OrderService",[149,600,601],{"class":178}," orderService",[149,603,604],{"class":155},";\n",[149,606,607],{"class":151,"line":245},[149,608,459],{"emptyLinePlaceholder":458},[149,610,611,613],{"class":151,"line":263},[149,612,464],{"class":155},[149,614,593],{"class":425},[149,616,617,620,623],{"class":151,"line":281},[149,618,619],{"class":425},"    OrderRepository",[149,621,622],{"class":178}," orderRepository",[149,624,604],{"class":155},[149,626,627],{"class":151,"line":298},[149,628,459],{"emptyLinePlaceholder":458},[149,630,631,633],{"class":151,"line":307},[149,632,464],{"class":155},[149,634,635],{"class":425},"Test\n",[149,637,638,641,644,646],{"class":151,"line":316},[149,639,640],{"class":425},"    void",[149,642,643],{"class":482}," createsOrderWithItems",[149,645,486],{"class":155},[149,647,453],{"class":155},[149,649,650,653,656,659,661,663,666,668,671,674,676,678,681,683,686,689,691,694,696,698,701,703,705,708,711,713],{"class":151,"line":333},[149,651,652],{"class":425},"        Long",[149,654,655],{"class":178}," id ",[149,657,658],{"class":155},"=",[149,660,601],{"class":178},[149,662,397],{"class":155},[149,664,665],{"class":482},"create",[149,667,429],{"class":155},[149,669,670],{"class":493},"new",[149,672,673],{"class":482}," CreateOrder",[149,675,429],{"class":155},[149,677,505],{"class":155},[149,679,680],{"class":508},"sukru",[149,682,505],{"class":155},[149,684,685],{"class":155},",",[149,687,688],{"class":178}," List",[149,690,397],{"class":155},[149,692,693],{"class":482},"of",[149,695,429],{"class":155},[149,697,505],{"class":155},[149,699,700],{"class":508},"book",[149,702,505],{"class":155},[149,704,685],{"class":155},[149,706,707],{"class":155}," \"",[149,709,710],{"class":508},"pen",[149,712,505],{"class":155},[149,714,715],{"class":155},")));\n",[149,717,718],{"class":151,"line":351},[149,719,459],{"emptyLinePlaceholder":458},[149,721,722,725,728,730,732,734,737,739,742,745,748],{"class":151,"line":368},[149,723,724],{"class":425},"        Order",[149,726,727],{"class":178}," order ",[149,729,658],{"class":155},[149,731,622],{"class":178},[149,733,397],{"class":155},[149,735,736],{"class":482},"findWithItemsById",[149,738,429],{"class":155},[149,740,741],{"class":178},"id",[149,743,744],{"class":155},").",[149,746,747],{"class":482},"orElseThrow",[149,749,750],{"class":155},"();\n",[149,752,754,757,759,762,764,767,770,773,775,779],{"class":151,"line":753},16,[149,755,756],{"class":482},"        assertThat",[149,758,429],{"class":155},[149,760,761],{"class":178},"order",[149,763,397],{"class":155},[149,765,766],{"class":482},"getItems",[149,768,769],{"class":155},"()).",[149,771,772],{"class":482},"hasSize",[149,774,429],{"class":155},[149,776,778],{"class":777},"sbssI","2",[149,780,514],{"class":155},[149,782,784],{"class":151,"line":783},17,[149,785,519],{"class":155},[149,787,789],{"class":151,"line":788},18,[149,790,524],{"class":155},[792,793,794],"blockquote",{},[15,795,796,797,530,800,803,804,807],{},"In Spring Boot 4, the test slice annotations (",[26,798,799],{},"@DataJpaTest",[26,801,802],{},"@WebMvcTest","...) moved into per-technology modules and their packages changed. Rather than memorizing import lines, let your IDE resolve them, and make sure the matching ",[26,805,806],{},"spring-boot-starter-*-test"," dependency is on the classpath.",[10,809,811],{"id":810},"_5-repository-test-with-datajpatest","5. Repository test with @DataJpaTest",[15,813,814,816],{},[26,815,799],{}," loads only the JPA layer and by default tries to replace the DataSource with an embedded database. To use the real container, we turn that off:",[140,818,820],{"className":413,"code":819,"language":415,"meta":145,"style":145},"@DataJpaTest\n@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)\n@Import(TestcontainersConfiguration.class)\nclass PostRepositoryTest {\n\n    @Autowired\n    PostRepository postRepository;\n\n    @Autowired\n    TestEntityManager em;\n\n    @Test\n    void findsPublishedPostsByTag() {\n        em.persist(new Post(\"Java 25\", \"java\", true));\n        em.persist(new Post(\"Draft\", \"java\", false));\n        em.flush();\n\n        assertThat(postRepository.findPublishedByTag(\"java\"))\n                .extracting(Post::getTitle)\n                .containsExactly(\"Java 25\");\n    }\n}\n",[26,821,822,829,858,874,883,887,893,903,907,913,923,927,933,944,983,1019,1030,1034,1059,1081,1099,1104],{"__ignoreMap":145},[149,823,824,826],{"class":151,"line":152},[149,825,422],{"class":155},[149,827,828],{"class":425},"DataJpaTest\n",[149,830,831,833,836,838,841,843,846,848,851,853,856],{"class":151,"line":166},[149,832,422],{"class":155},[149,834,835],{"class":425},"AutoConfigureTestDatabase",[149,837,429],{"class":155},[149,839,840],{"class":432},"replace",[149,842,436],{"class":155},[149,844,845],{"class":178}," AutoConfigureTestDatabase",[149,847,397],{"class":155},[149,849,850],{"class":178},"Replace",[149,852,397],{"class":155},[149,854,855],{"class":178},"NONE",[149,857,573],{"class":155},[149,859,860,862,864,866,868,870,872],{"class":151,"line":189},[149,861,422],{"class":155},[149,863,560],{"class":425},[149,865,429],{"class":155},[149,867,565],{"class":178},[149,869,397],{"class":155},[149,871,570],{"class":178},[149,873,573],{"class":155},[149,875,876,878,881],{"class":151,"line":208},[149,877,570],{"class":425},[149,879,880],{"class":432}," PostRepositoryTest",[149,882,453],{"class":155},[149,884,885],{"class":151,"line":227},[149,886,459],{"emptyLinePlaceholder":458},[149,888,889,891],{"class":151,"line":236},[149,890,464],{"class":155},[149,892,593],{"class":425},[149,894,895,898,901],{"class":151,"line":245},[149,896,897],{"class":425},"    PostRepository",[149,899,900],{"class":178}," postRepository",[149,902,604],{"class":155},[149,904,905],{"class":151,"line":263},[149,906,459],{"emptyLinePlaceholder":458},[149,908,909,911],{"class":151,"line":281},[149,910,464],{"class":155},[149,912,593],{"class":425},[149,914,915,918,921],{"class":151,"line":298},[149,916,917],{"class":425},"    TestEntityManager",[149,919,920],{"class":178}," em",[149,922,604],{"class":155},[149,924,925],{"class":151,"line":307},[149,926,459],{"emptyLinePlaceholder":458},[149,928,929,931],{"class":151,"line":316},[149,930,464],{"class":155},[149,932,635],{"class":425},[149,934,935,937,940,942],{"class":151,"line":333},[149,936,640],{"class":425},[149,938,939],{"class":482}," findsPublishedPostsByTag",[149,941,486],{"class":155},[149,943,453],{"class":155},[149,945,946,949,951,954,956,958,961,963,965,968,970,972,974,976,978,980],{"class":151,"line":351},[149,947,948],{"class":178},"        em",[149,950,397],{"class":155},[149,952,953],{"class":482},"persist",[149,955,429],{"class":155},[149,957,670],{"class":493},[149,959,960],{"class":482}," Post",[149,962,429],{"class":155},[149,964,505],{"class":155},[149,966,967],{"class":508},"Java 25",[149,969,505],{"class":155},[149,971,685],{"class":155},[149,973,707],{"class":155},[149,975,415],{"class":508},[149,977,505],{"class":155},[149,979,685],{"class":155},[149,981,982],{"class":155}," true));\n",[149,984,985,987,989,991,993,995,997,999,1001,1004,1006,1008,1010,1012,1014,1016],{"class":151,"line":368},[149,986,948],{"class":178},[149,988,397],{"class":155},[149,990,953],{"class":482},[149,992,429],{"class":155},[149,994,670],{"class":493},[149,996,960],{"class":482},[149,998,429],{"class":155},[149,1000,505],{"class":155},[149,1002,1003],{"class":508},"Draft",[149,1005,505],{"class":155},[149,1007,685],{"class":155},[149,1009,707],{"class":155},[149,1011,415],{"class":508},[149,1013,505],{"class":155},[149,1015,685],{"class":155},[149,1017,1018],{"class":155}," false));\n",[149,1020,1021,1023,1025,1028],{"class":151,"line":753},[149,1022,948],{"class":178},[149,1024,397],{"class":155},[149,1026,1027],{"class":482},"flush",[149,1029,750],{"class":155},[149,1031,1032],{"class":151,"line":783},[149,1033,459],{"emptyLinePlaceholder":458},[149,1035,1036,1038,1040,1043,1045,1048,1050,1052,1054,1056],{"class":151,"line":788},[149,1037,756],{"class":482},[149,1039,429],{"class":155},[149,1041,1042],{"class":178},"postRepository",[149,1044,397],{"class":155},[149,1046,1047],{"class":482},"findPublishedByTag",[149,1049,429],{"class":155},[149,1051,505],{"class":155},[149,1053,415],{"class":508},[149,1055,505],{"class":155},[149,1057,1058],{"class":155},"))\n",[149,1060,1062,1065,1068,1070,1073,1076,1079],{"class":151,"line":1061},19,[149,1063,1064],{"class":155},"                .",[149,1066,1067],{"class":482},"extracting",[149,1069,429],{"class":155},[149,1071,1072],{"class":178},"Post",[149,1074,1075],{"class":493},"::",[149,1077,1078],{"class":178},"getTitle",[149,1080,573],{"class":155},[149,1082,1084,1086,1089,1091,1093,1095,1097],{"class":151,"line":1083},20,[149,1085,1064],{"class":155},[149,1087,1088],{"class":482},"containsExactly",[149,1090,429],{"class":155},[149,1092,505],{"class":155},[149,1094,967],{"class":508},[149,1096,505],{"class":155},[149,1098,514],{"class":155},[149,1100,1102],{"class":151,"line":1101},21,[149,1103,519],{"class":155},[149,1105,1107],{"class":151,"line":1106},22,[149,1108,524],{"class":155},[15,1110,1111,1113],{},[26,1112,799],{}," runs each test in a transaction and rolls it back at the end; tests don't see each other's data.",[10,1115,1117],{"id":1116},"_6-running-flyway-migrations-in-tests","6. Running Flyway migrations in tests",[15,1119,1120,1121,1124,1125,1128],{},"If you manage the schema with migrations rather than ",[26,1122,1123],{},"ddl-auto"," (the recommended way), tests should start with the same migrations. If Flyway is on the classpath, Spring Boot runs the scripts under ",[26,1126,1127],{},"db\u002Fmigration"," as soon as it connects to the container:",[140,1130,1134],{"className":1131,"code":1132,"language":1133,"meta":145,"style":145},"language-properties shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","# src\u002Ftest\u002Fresources\u002Fapplication-test.properties\nspring.jpa.hibernate.ddl-auto=validate\nspring.flyway.enabled=true\n","properties",[26,1135,1136,1142,1152],{"__ignoreMap":145},[149,1137,1138],{"class":151,"line":152},[149,1139,1141],{"class":1140},"sHwdD","# src\u002Ftest\u002Fresources\u002Fapplication-test.properties\n",[149,1143,1144,1147,1149],{"class":151,"line":166},[149,1145,1146],{"class":159},"spring.jpa.hibernate.ddl-auto",[149,1148,658],{"class":155},[149,1150,1151],{"class":178},"validate\n",[149,1153,1154,1157,1159],{"class":151,"line":189},[149,1155,1156],{"class":159},"spring.flyway.enabled",[149,1158,658],{"class":155},[149,1160,1161],{"class":178},"true\n",[15,1163,1164,1165,1168,1169,1172,1173,1176],{},"In Spring Boot 4, Flyway support comes from ",[26,1166,1167],{},"spring-boot-starter-flyway","; for PostgreSQL you also need ",[26,1170,1171],{},"flyway-database-postgresql",". With ",[26,1174,1175],{},"ddl-auto=validate",", mismatches between entities and migrations are caught in tests.",[10,1178,1180],{"id":1179},"_7-n1-regression-test-counting-queries","7. N+1 regression test: counting queries",[15,1182,1183],{},"The best way to make the fix from the Hibernate N+1 post stick is to test the number of queries executed. Enable Hibernate statistics in the test profile:",[140,1185,1187],{"className":1131,"code":1186,"language":1133,"meta":145,"style":145},"spring.jpa.properties.hibernate.generate_statistics=true\n",[26,1188,1189],{"__ignoreMap":145},[149,1190,1191,1194,1196],{"class":151,"line":152},[149,1192,1193],{"class":159},"spring.jpa.properties.hibernate.generate_statistics",[149,1195,658],{"class":155},[149,1197,1161],{"class":178},[140,1199,1201],{"className":413,"code":1200,"language":415,"meta":145,"style":145},"@DataJpaTest\n@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)\n@Import(TestcontainersConfiguration.class)\nclass PostQueryCountTest {\n\n    @Autowired\n    PostRepository postRepository;\n\n    @Autowired\n    EntityManagerFactory emf;\n\n    @Test\n    void loadsPostsWithCommentsInSingleQuery() {\n        \u002F\u002F test data: 10 posts with 3 comments each...\n\n        Statistics stats = emf.unwrap(SessionFactory.class).getStatistics();\n        stats.clear();\n\n        List\u003CPost> posts = postRepository.findAllWithComments();\n        posts.forEach(p -> p.getComments().size());   \u002F\u002F touch the lazy collections\n\n        assertThat(stats.getPrepareStatementCount()).isEqualTo(1);\n    }\n}\n",[26,1202,1203,1209,1233,1249,1258,1262,1268,1276,1280,1286,1296,1300,1306,1317,1322,1326,1359,1371,1375,1400,1438,1442,1468,1473],{"__ignoreMap":145},[149,1204,1205,1207],{"class":151,"line":152},[149,1206,422],{"class":155},[149,1208,828],{"class":425},[149,1210,1211,1213,1215,1217,1219,1221,1223,1225,1227,1229,1231],{"class":151,"line":166},[149,1212,422],{"class":155},[149,1214,835],{"class":425},[149,1216,429],{"class":155},[149,1218,840],{"class":432},[149,1220,436],{"class":155},[149,1222,845],{"class":178},[149,1224,397],{"class":155},[149,1226,850],{"class":178},[149,1228,397],{"class":155},[149,1230,855],{"class":178},[149,1232,573],{"class":155},[149,1234,1235,1237,1239,1241,1243,1245,1247],{"class":151,"line":189},[149,1236,422],{"class":155},[149,1238,560],{"class":425},[149,1240,429],{"class":155},[149,1242,565],{"class":178},[149,1244,397],{"class":155},[149,1246,570],{"class":178},[149,1248,573],{"class":155},[149,1250,1251,1253,1256],{"class":151,"line":208},[149,1252,570],{"class":425},[149,1254,1255],{"class":432}," PostQueryCountTest",[149,1257,453],{"class":155},[149,1259,1260],{"class":151,"line":227},[149,1261,459],{"emptyLinePlaceholder":458},[149,1263,1264,1266],{"class":151,"line":236},[149,1265,464],{"class":155},[149,1267,593],{"class":425},[149,1269,1270,1272,1274],{"class":151,"line":245},[149,1271,897],{"class":425},[149,1273,900],{"class":178},[149,1275,604],{"class":155},[149,1277,1278],{"class":151,"line":263},[149,1279,459],{"emptyLinePlaceholder":458},[149,1281,1282,1284],{"class":151,"line":281},[149,1283,464],{"class":155},[149,1285,593],{"class":425},[149,1287,1288,1291,1294],{"class":151,"line":298},[149,1289,1290],{"class":425},"    EntityManagerFactory",[149,1292,1293],{"class":178}," emf",[149,1295,604],{"class":155},[149,1297,1298],{"class":151,"line":307},[149,1299,459],{"emptyLinePlaceholder":458},[149,1301,1302,1304],{"class":151,"line":316},[149,1303,464],{"class":155},[149,1305,635],{"class":425},[149,1307,1308,1310,1313,1315],{"class":151,"line":333},[149,1309,640],{"class":425},[149,1311,1312],{"class":482}," loadsPostsWithCommentsInSingleQuery",[149,1314,486],{"class":155},[149,1316,453],{"class":155},[149,1318,1319],{"class":151,"line":351},[149,1320,1321],{"class":1140},"        \u002F\u002F test data: 10 posts with 3 comments each...\n",[149,1323,1324],{"class":151,"line":368},[149,1325,459],{"emptyLinePlaceholder":458},[149,1327,1328,1331,1334,1336,1338,1340,1343,1345,1348,1350,1352,1354,1357],{"class":151,"line":753},[149,1329,1330],{"class":425},"        Statistics",[149,1332,1333],{"class":178}," stats ",[149,1335,658],{"class":155},[149,1337,1293],{"class":178},[149,1339,397],{"class":155},[149,1341,1342],{"class":482},"unwrap",[149,1344,429],{"class":155},[149,1346,1347],{"class":178},"SessionFactory",[149,1349,397],{"class":155},[149,1351,570],{"class":178},[149,1353,744],{"class":155},[149,1355,1356],{"class":482},"getStatistics",[149,1358,750],{"class":155},[149,1360,1361,1364,1366,1369],{"class":151,"line":783},[149,1362,1363],{"class":178},"        stats",[149,1365,397],{"class":155},[149,1367,1368],{"class":482},"clear",[149,1370,750],{"class":155},[149,1372,1373],{"class":151,"line":788},[149,1374,459],{"emptyLinePlaceholder":458},[149,1376,1377,1380,1382,1384,1386,1389,1391,1393,1395,1398],{"class":151,"line":1061},[149,1378,1379],{"class":425},"        List",[149,1381,156],{"class":155},[149,1383,1072],{"class":425},[149,1385,175],{"class":155},[149,1387,1388],{"class":178}," posts ",[149,1390,658],{"class":155},[149,1392,900],{"class":178},[149,1394,397],{"class":155},[149,1396,1397],{"class":482},"findAllWithComments",[149,1399,750],{"class":155},[149,1401,1402,1405,1407,1410,1412,1415,1418,1421,1423,1426,1429,1432,1435],{"class":151,"line":1083},[149,1403,1404],{"class":178},"        posts",[149,1406,397],{"class":155},[149,1408,1409],{"class":482},"forEach",[149,1411,429],{"class":155},[149,1413,1414],{"class":178},"p ",[149,1416,1417],{"class":425},"->",[149,1419,1420],{"class":178}," p",[149,1422,397],{"class":155},[149,1424,1425],{"class":482},"getComments",[149,1427,1428],{"class":155},"().",[149,1430,1431],{"class":482},"size",[149,1433,1434],{"class":155},"());",[149,1436,1437],{"class":1140},"   \u002F\u002F touch the lazy collections\n",[149,1439,1440],{"class":151,"line":1101},[149,1441,459],{"emptyLinePlaceholder":458},[149,1443,1444,1446,1448,1451,1453,1456,1458,1461,1463,1466],{"class":151,"line":1106},[149,1445,756],{"class":482},[149,1447,429],{"class":155},[149,1449,1450],{"class":178},"stats",[149,1452,397],{"class":155},[149,1454,1455],{"class":482},"getPrepareStatementCount",[149,1457,769],{"class":155},[149,1459,1460],{"class":482},"isEqualTo",[149,1462,429],{"class":155},[149,1464,1465],{"class":777},"1",[149,1467,514],{"class":155},[149,1469,1471],{"class":151,"line":1470},23,[149,1472,519],{"class":155},[149,1474,1476],{"class":151,"line":1475},24,[149,1477,524],{"class":155},[15,1479,1480,1481,1484,1485,1488],{},"If someone removes the ",[26,1482,1483],{},"JOIN FETCH"," or ",[26,1486,1487],{},"@EntityGraph",", the query count jumps to 11 and the test fails.",[10,1490,1492],{"id":1491},"_8-container-reuse-and-the-singleton-container","8. Container reuse and the singleton container",[15,1494,1495],{},"Starting a new container for every test class is slow. There are two common solutions:",[15,1497,1498,1501,1502,1505,1506,1509],{},[21,1499,1500],{},"Spring context cache:"," Test classes that use the same configuration (",[26,1503,1504],{},"@Import(TestcontainersConfiguration.class)",") share the same Spring context and therefore the same container. Unnecessary ",[26,1507,1508],{},"@MockitoBean","s or differing properties in test classes split the context; keep them to a minimum.",[15,1511,1512,1515],{},[21,1513,1514],{},"Reuse for local development:"," To keep the container up between test runs as well:",[140,1517,1519],{"className":413,"code":1518,"language":415,"meta":145,"style":145},"return new PostgreSQLContainer(\"postgres:17-alpine\").withReuse(true);\n",[26,1520,1521],{"__ignoreMap":145},[149,1522,1523,1526,1528,1530,1532,1534,1536,1538,1540,1543],{"class":151,"line":152},[149,1524,1525],{"class":493},"return",[149,1527,497],{"class":493},[149,1529,500],{"class":482},[149,1531,429],{"class":155},[149,1533,505],{"class":155},[149,1535,509],{"class":508},[149,1537,505],{"class":155},[149,1539,744],{"class":155},[149,1541,1542],{"class":482},"withReuse",[149,1544,1545],{"class":155},"(true);\n",[140,1547,1549],{"className":1131,"code":1548,"language":1133,"meta":145,"style":145},"# ~\u002F.testcontainers.properties\ntestcontainers.reuse.enable=true\n",[26,1550,1551,1556],{"__ignoreMap":145},[149,1552,1553],{"class":151,"line":152},[149,1554,1555],{"class":1140},"# ~\u002F.testcontainers.properties\n",[149,1557,1558,1561,1563],{"class":151,"line":166},[149,1559,1560],{"class":159},"testcontainers.reuse.enable",[149,1562,658],{"class":155},[149,1564,1161],{"class":178},[15,1566,1567],{},"Reuse only works on machines where this setting is enabled; it's safer to leave it off in CI and use a clean container on every run. With reuse enabled, data persists between runs, so make sure your tests clean up their own data.",[10,1569,1571],{"id":1570},"_9-the-older-way-dynamicpropertysource","9. The older way: @DynamicPropertySource",[15,1573,1574,1575,1577],{},"Before ",[26,1576,28],{},", or for an unsupported service, container details are passed as properties:",[140,1579,1581],{"className":413,"code":1580,"language":415,"meta":145,"style":145},"@SpringBootTest\n@Testcontainers\nclass LegacyStyleIT {\n\n    @Container\n    static PostgreSQLContainer postgres = new PostgreSQLContainer(\"postgres:17-alpine\");\n\n    @DynamicPropertySource\n    static void props(DynamicPropertyRegistry registry) {\n        registry.add(\"spring.datasource.url\", postgres::getJdbcUrl);\n        registry.add(\"spring.datasource.username\", postgres::getUsername);\n        registry.add(\"spring.datasource.password\", postgres::getPassword);\n    }\n}\n",[26,1582,1583,1589,1596,1605,1609,1616,1642,1646,1653,1677,1706,1734,1762,1766],{"__ignoreMap":145},[149,1584,1585,1587],{"class":151,"line":152},[149,1586,422],{"class":155},[149,1588,553],{"class":425},[149,1590,1591,1593],{"class":151,"line":166},[149,1592,422],{"class":155},[149,1594,1595],{"class":425},"Testcontainers\n",[149,1597,1598,1600,1603],{"class":151,"line":189},[149,1599,570],{"class":425},[149,1601,1602],{"class":432}," LegacyStyleIT",[149,1604,453],{"class":155},[149,1606,1607],{"class":151,"line":208},[149,1608,459],{"emptyLinePlaceholder":458},[149,1610,1611,1613],{"class":151,"line":227},[149,1612,464],{"class":155},[149,1614,1615],{"class":425},"Container\n",[149,1617,1618,1621,1623,1626,1628,1630,1632,1634,1636,1638,1640],{"class":151,"line":236},[149,1619,1620],{"class":425},"    static",[149,1622,500],{"class":425},[149,1624,1625],{"class":178}," postgres ",[149,1627,658],{"class":155},[149,1629,497],{"class":493},[149,1631,500],{"class":482},[149,1633,429],{"class":155},[149,1635,505],{"class":155},[149,1637,509],{"class":508},[149,1639,505],{"class":155},[149,1641,514],{"class":155},[149,1643,1644],{"class":151,"line":245},[149,1645,459],{"emptyLinePlaceholder":458},[149,1647,1648,1650],{"class":151,"line":263},[149,1649,464],{"class":155},[149,1651,1652],{"class":425},"DynamicPropertySource\n",[149,1654,1655,1657,1660,1663,1665,1668,1672,1675],{"class":151,"line":281},[149,1656,1620],{"class":425},[149,1658,1659],{"class":425}," void",[149,1661,1662],{"class":482}," props",[149,1664,429],{"class":155},[149,1666,1667],{"class":425},"DynamicPropertyRegistry",[149,1669,1671],{"class":1670},"sHdIc"," registry",[149,1673,1674],{"class":155},")",[149,1676,453],{"class":155},[149,1678,1679,1682,1684,1687,1689,1691,1693,1695,1697,1699,1701,1704],{"class":151,"line":298},[149,1680,1681],{"class":178},"        registry",[149,1683,397],{"class":155},[149,1685,1686],{"class":482},"add",[149,1688,429],{"class":155},[149,1690,505],{"class":155},[149,1692,533],{"class":508},[149,1694,505],{"class":155},[149,1696,685],{"class":155},[149,1698,483],{"class":178},[149,1700,1075],{"class":493},[149,1702,1703],{"class":178},"getJdbcUrl",[149,1705,514],{"class":155},[149,1707,1708,1710,1712,1714,1716,1718,1721,1723,1725,1727,1729,1732],{"class":151,"line":307},[149,1709,1681],{"class":178},[149,1711,397],{"class":155},[149,1713,1686],{"class":482},[149,1715,429],{"class":155},[149,1717,505],{"class":155},[149,1719,1720],{"class":508},"spring.datasource.username",[149,1722,505],{"class":155},[149,1724,685],{"class":155},[149,1726,483],{"class":178},[149,1728,1075],{"class":493},[149,1730,1731],{"class":178},"getUsername",[149,1733,514],{"class":155},[149,1735,1736,1738,1740,1742,1744,1746,1749,1751,1753,1755,1757,1760],{"class":151,"line":316},[149,1737,1681],{"class":178},[149,1739,397],{"class":155},[149,1741,1686],{"class":482},[149,1743,429],{"class":155},[149,1745,505],{"class":155},[149,1747,1748],{"class":508},"spring.datasource.password",[149,1750,505],{"class":155},[149,1752,685],{"class":155},[149,1754,483],{"class":178},[149,1756,1075],{"class":493},[149,1758,1759],{"class":178},"getPassword",[149,1761,514],{"class":155},[149,1763,1764],{"class":151,"line":333},[149,1765,519],{"class":155},[149,1767,1768],{"class":151,"line":351},[149,1769,524],{"class":155},[15,1771,1772,1773,1775],{},"It works, but you need to know the property names for every service; prefer ",[26,1774,28],{}," wherever possible.",[10,1777,1779],{"id":1778},"_10-running-the-app-locally-with-containers","10. Running the app locally with containers",[15,1781,1782,1783,1786,1787,410],{},"You can use the same configuration during development. Define a ",[26,1784,1785],{},"main"," method under ",[26,1788,1789],{},"src\u002Ftest\u002Fjava",[140,1791,1793],{"className":413,"code":1792,"language":415,"meta":145,"style":145},"public class TestApplication {\n\n    public static void main(String[] args) {\n        SpringApplication.from(Application::main)\n                .with(TestcontainersConfiguration.class)\n                .run(args);\n    }\n}\n",[26,1794,1795,1806,1810,1838,1859,1876,1890,1894],{"__ignoreMap":145},[149,1796,1797,1799,1801,1804],{"class":151,"line":152},[149,1798,444],{"class":425},[149,1800,447],{"class":425},[149,1802,1803],{"class":432}," TestApplication",[149,1805,453],{"class":155},[149,1807,1808],{"class":151,"line":166},[149,1809,459],{"emptyLinePlaceholder":458},[149,1811,1812,1815,1818,1820,1823,1825,1828,1831,1834,1836],{"class":151,"line":189},[149,1813,1814],{"class":425},"    public",[149,1816,1817],{"class":425}," static",[149,1819,1659],{"class":425},[149,1821,1822],{"class":482}," main",[149,1824,429],{"class":155},[149,1826,1827],{"class":425},"String",[149,1829,1830],{"class":155},"[]",[149,1832,1833],{"class":1670}," args",[149,1835,1674],{"class":155},[149,1837,453],{"class":155},[149,1839,1840,1843,1845,1848,1850,1853,1855,1857],{"class":151,"line":208},[149,1841,1842],{"class":178},"        SpringApplication",[149,1844,397],{"class":155},[149,1846,1847],{"class":482},"from",[149,1849,429],{"class":155},[149,1851,1852],{"class":178},"Application",[149,1854,1075],{"class":493},[149,1856,1785],{"class":178},[149,1858,573],{"class":155},[149,1860,1861,1863,1866,1868,1870,1872,1874],{"class":151,"line":227},[149,1862,1064],{"class":155},[149,1864,1865],{"class":482},"with",[149,1867,429],{"class":155},[149,1869,565],{"class":178},[149,1871,397],{"class":155},[149,1873,570],{"class":178},[149,1875,573],{"class":155},[149,1877,1878,1880,1883,1885,1888],{"class":151,"line":236},[149,1879,1064],{"class":155},[149,1881,1882],{"class":482},"run",[149,1884,429],{"class":155},[149,1886,1887],{"class":178},"args",[149,1889,514],{"class":155},[149,1891,1892],{"class":151,"line":245},[149,1893,519],{"class":155},[149,1895,1896],{"class":151,"line":263},[149,1897,524],{"class":155},[15,1899,1900,1901,1904,1905,1908,1909,1912],{},"When you run ",[26,1902,1903],{},"TestApplication"," from the IDE, the PostgreSQL container starts and the app connects to it; everyone on the team works with the same environment without installing a database locally. ",[26,1906,1907],{},".\u002Fmvnw spring-boot:test-run"," with Maven and ",[26,1910,1911],{},".\u002Fgradlew bootTestRun"," with Gradle do the same.",[10,1914,1916],{"id":1915},"_11-running-in-ci","11. Running in CI",[15,1918,1919,1920,1923],{},"GitHub Actions ",[26,1921,1922],{},"ubuntu-latest"," runners come with Docker ready; no extra setup is needed:",[140,1925,1929],{"className":1926,"code":1927,"language":1928,"meta":145,"style":145},"language-yaml shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","- uses: actions\u002Fsetup-java@v4\n  with:\n    distribution: temurin\n    java-version: 25\n    cache: maven\n\n- name: Test\n  run: .\u002Fmvnw -B verify\n","yaml",[26,1930,1931,1944,1952,1962,1972,1982,1986,1998],{"__ignoreMap":145},[149,1932,1933,1936,1939,1941],{"class":151,"line":152},[149,1934,1935],{"class":155},"-",[149,1937,1938],{"class":159}," uses",[149,1940,410],{"class":155},[149,1942,1943],{"class":508}," actions\u002Fsetup-java@v4\n",[149,1945,1946,1949],{"class":151,"line":166},[149,1947,1948],{"class":159},"  with",[149,1950,1951],{"class":155},":\n",[149,1953,1954,1957,1959],{"class":151,"line":189},[149,1955,1956],{"class":159},"    distribution",[149,1958,410],{"class":155},[149,1960,1961],{"class":508}," temurin\n",[149,1963,1964,1967,1969],{"class":151,"line":208},[149,1965,1966],{"class":159},"    java-version",[149,1968,410],{"class":155},[149,1970,1971],{"class":777}," 25\n",[149,1973,1974,1977,1979],{"class":151,"line":227},[149,1975,1976],{"class":159},"    cache",[149,1978,410],{"class":155},[149,1980,1981],{"class":508}," maven\n",[149,1983,1984],{"class":151,"line":236},[149,1985,459],{"emptyLinePlaceholder":458},[149,1987,1988,1990,1993,1995],{"class":151,"line":245},[149,1989,1935],{"class":155},[149,1991,1992],{"class":159}," name",[149,1994,410],{"class":155},[149,1996,1997],{"class":508}," Test\n",[149,1999,2000,2003,2005],{"class":151,"line":263},[149,2001,2002],{"class":159},"  run",[149,2004,410],{"class":155},[149,2006,2007],{"class":508}," .\u002Fmvnw -B verify\n",[15,2009,2010],{},"For the details of setting up the pipeline, see the CI\u002FCD with GitHub Actions post. A few tips:",[2012,2013,2014,2024,2035],"ul",{},[2015,2016,2017,2018,2020,2021,397],"li",{},"Use images with a fixed tag (",[26,2019,509],{},"), not ",[26,2022,2023],{},"latest",[2015,2025,2026,2027,2030,2031,2034],{},"If you separate unit tests (",[26,2028,2029],{},"*Test",") from container tests (",[26,2032,2033],{},"*IT","), you get fast feedback with Surefire\u002FFailsafe.",[2015,2036,2037],{},"Developers on macOS\u002FWindows need Docker Desktop or a compatible alternative.",[10,2039,2041],{"id":2040},"conclusion","Conclusion",[15,2043,2044,2045,2047],{},"Testcontainers removes H2's \"passed in tests, blew up in production\" problem: your tests run against real PostgreSQL, with real migrations and real lock behavior. Spring Boot's ",[26,2046,28],{}," support reduces the configuration to a single bean, and you can reuse that bean for local development. Test the N+1, transaction and locking topics from the Hibernate and Spring series on this setup to make sure your fixes stay fixed.",[2049,2050,2051],"style",{},"html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}",{"title":145,"searchDepth":166,"depth":166,"links":2053},[2054,2055,2056,2057,2058,2059,2060,2061,2062,2063,2064,2065,2066],{"id":12,"depth":166,"text":13},{"id":32,"depth":166,"text":33},{"id":137,"depth":166,"text":138},{"id":403,"depth":166,"text":404},{"id":540,"depth":166,"text":541},{"id":810,"depth":166,"text":811},{"id":1116,"depth":166,"text":1117},{"id":1179,"depth":166,"text":1180},{"id":1491,"depth":166,"text":1492},{"id":1570,"depth":166,"text":1571},{"id":1778,"depth":166,"text":1779},{"id":1915,"depth":166,"text":1916},{"id":2040,"depth":166,"text":2041},"2026-11-26","Testing against real PostgreSQL instead of H2: @ServiceConnection, @DataJpaTest, Flyway migrations, an N+1 regression test by counting queries, container reuse and running the app locally with containers.","md",{},"\u002Fen\u002Fblog\u002Fspring-boot-testcontainers",{"title":5,"description":2068},"en\u002Fblog\u002Fspring-boot-testcontainers",[415,2075,2076,2077,2078],"spring","hibernate","docker","guide","\u002Fblog\u002Fspring-boot-testcontainers","VCcsz-4iWiLwh52YUsNQU_z1lduTxYxzxcBaTV_FzgU",[2082,2090,2096],{"path":2083,"title":2084,"description":2085,"date":2086,"tags":2087},"\u002Fen\u002Fblog\u002Fspring-ai-rag-pgvector","RAG with Spring AI and PostgreSQL pgvector","An app that answers questions over your own documents: generating embeddings with Spring AI, storing them in pgvector, similarity search, and enriching the prompt with QuestionAnswerAdvisor.","2026-11-25",[415,2075,2088,2089,396,2078],"spring-ai","ai",{"path":2091,"title":2092,"description":2093,"date":2094,"tags":2095},"\u002Fen\u002Fblog\u002Fspring-ai-tool-calling-mcp","Tool Calling and MCP with Spring AI","Exposing your application's functions to an LLM with Spring AI — tool calling with @Tool, ToolContext, returnDirect, security, and setting up a Model Context Protocol (MCP) server and client.","2026-11-24",[415,2075,2088,2089,2078],{"path":2097,"title":2098,"description":2099,"date":2100,"tags":2101},"\u002Fen\u002Fblog\u002Fspring-ai-getting-started","Getting Started with Spring AI: ChatClient, Prompts, Structured Output and Chat Memory","Adding LLM support to a Spring Boot app with Spring AI — setup, the ChatClient API, prompt templates, structured output into records, streaming and conversation memory.","2026-11-23",[415,2075,2088,2089,2078],1795663771118]