{"id":336695,"date":"2022-08-07T15:00:24","date_gmt":"2022-08-07T15:00:24","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336695"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336695","title":{"rendered":"<span>Spring Test Containers \u043a\u0430\u043a \u0431\u0438\u043d\u044b<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2b5\/766\/eed\/2b5766eedbdd919197413628398c69c2.png\" width=\"880\" height=\"440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2b5\/766\/eed\/2b5766eedbdd919197413628398c69c2.png\"\/><figcaption><\/figcaption><\/figure>\n<ol>\n<li>\n<p><a href=\"#%D0%92%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%A2%D0%B5%D0%BE%D1%80%D0%B8%D1%8F\" rel=\"noopener noreferrer nofollow\">\u0422\u0435\u043e\u0440\u0438\u044f<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%97%D0%B0%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D0%B8\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0438<\/a><\/p>\n<\/li>\n<\/ol>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p><a class=\"anchor\" name=\"%D0%92%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5\" id=\"\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435\"><\/a><\/p>\n<p>TestContainers \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043e\u0449\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/www.testcontainers.org\/\" rel=\"noopener noreferrer nofollow\">\u043d\u0430 \u043e\u0444 \u0441\u0430\u0439\u0442\u0435<\/a>, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/company\/jugru\/blog\/343298\/\" rel=\"noopener noreferrer nofollow\">\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440\u0435<\/a>. <\/p>\n<p>\u0422\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 junit4 (\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 <a href=\"https:\/\/habr.com\/ru\/company\/haulmont\/blog\/454970\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>, <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/514270\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>), \u0430 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u0447\u0435\u0440\u0435\u0437 junit5 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c DynamicPropertySource (\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/habr.com\/ru\/post\/561520\/\" rel=\"noopener noreferrer nofollow\">\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>) \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b, \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439. <\/p>\n<p>\u0422\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0430\u0437\u044b + \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u0438 \u0442.\u0434., \u0432 \u043e\u0431\u0449\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <u>\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432<\/u>, <u>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c properties<\/u> \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<p>\u0418 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c spring-beans \u2013 dependsOn.<\/p>\n<h2>\u0422\u0435\u043e\u0440\u0438\u044f<\/h2>\n<p><a class=\"anchor\" name=\"%D0%A2%D0%B5%D0%BE%D1%80%D0%B8%D1%8F\" id=\"\u0422\u0435\u043e\u0440\u0438\u044f\"><\/a><\/p>\n<p>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 + \u0442\u0435\u0441\u0442\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 + \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<p>Spring \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u042d\u0442\u0438\u043c \u043c\u044b \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b:<\/p>\n<ol>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c Bean \u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u00ab.properties\u00bb \u0444\u0430\u0439\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u0414\u041e \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u043d\u0451\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u044d\u0442\u043e\u0439 \u0441\u0430\u043c\u043e\u0439 \u0411\u0414<\/p>\n<\/li>\n<li>\n<p>\u0418 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c BeanFactoryPostProcessor (\u043a\u0430\u043a \u0434\u0430\u043d\u044c \u0443\u0432\u0430\u0436\u0435\u043d\u0438\u044f \u0415\u0432\u0433\u0435\u043d\u0438\u044e \u0411\u043e\u0440\u0438\u0441\u043e\u0432\u0443 \ud83d\ude09 ), \u0442.\u043a. \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <abbr title=\"BeanFactoryPostProcessor\" type=\"abbr\">BFPP <\/abbr>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 BeanDefinition\u2019\u0430\u043c\u0438 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e \u043d\u0438\u043c \u043d\u0430\u0447\u043d\u0443\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c\u0441\u044f \u0431\u0438\u043d\u044b. \u042d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043a\u0430\u043a \u0440\u0430\u0437 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432.<\/p>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h2>\n<p><a class=\"anchor\" name=\"%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D0%BA%D0%B0\" id=\"\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\"><\/a><\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0431\u0438\u043d \u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c<\/p>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0442\u043e \u0437\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d: \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c image, \u043b\u043e\u0433\u0438\u043d, \u043f\u0430\u0440\u043e\u043b\u044c, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0440\u0442 (\u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0434\u0435\u0431\u0430\u0433\u0435)<\/p>\n<pre><code class=\"java\">public class PostgresContainer {  \u00a0\u00a0\u00a0 private final PostgreSQLContainer&lt;?> postgreSQLContainer;  \u00a0\u00a0\u00a0 public PostgresContainer() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer = new PostgreSQLContainer&lt;>(DockerImageName.parse(\"postgres:14.3\"))3\")) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withDatabaseName(\"postgres\") \u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.withUsername(\"postgres\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withPassword(\"example\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withExposedPorts(5432) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; \u00a0\u00a0\u00a0 } }<\/code><\/pre>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0432 PostConstruct.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430. <\/p>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u0441\u0442\u0430 \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441<\/p>\n<pre><code class=\"java\">public class PostgresContainer {  \u00a0\u00a0\u00a0 private final PostgreSQLContainer&lt;?> postgreSQLContainer;  \u00a0\u00a0\u00a0 public PostgresContainer() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer = new PostgreSQLContainer&lt;>(DockerImageName.parse(\"postgres:14.3\")) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withDatabaseName(\"postgres\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withUsername(\"postgres\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withPassword(\"example\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withExposedPorts(5432) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @PostConstruct \u00a0\u00a0\u00a0 public void start() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer.start();  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.setProperty(\"spring.datasource.url\", postgreSQLContainer.getJdbcUrl()); \u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0System.setProperty(\"spring.datasource.username\", postgreSQLContainer.getUsername()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.setProperty(\"spring.datasource.password\", postgreSQLContainer.getPassword()); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @PreDestroy \u00a0\u00a0\u00a0 public void stop() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer.stop(); \u00a0\u00a0\u00a0 } }<\/code><\/pre>\n<p>\u00a0<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u043b \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u0435 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e \u0431\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u0438\u043d\u043e\u0432. <\/p>\n<pre><code class=\"java\">@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface AutoConfigurePostgresContainer {  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430, \u0432 BeanDefinition \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430 #{@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 String beanNameThatNeedsToDependOnContainer() default \"\";  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u041a\u043b\u0430\u0441\u0441 \u0431\u0438\u043d\u0430, \u0432 BeanDefinition \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430 #{@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 Class&lt;?> beanClassNameThatNeedsToDependOnContainer() default Void.class;  }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 \u0441 \u0441\u0430\u043c\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c (\u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043a\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432). \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 \u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0430\u0440\u0442\u0430 \u0431\u0438\u043d\u043e\u0432. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438 \u0442.\u043f.<\/p>\n<p>4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c <abbr title=\"BeanFactoryPostProcessor\" type=\"abbr\">BFPP <\/abbr>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439<\/p>\n<pre><code class=\"java\">public class DependsOnContainerSetterBFPP implements BeanFactoryPostProcessor, Ordered {  \u00a0\u00a0\u00a0 private final AutoConfigurePostgresContainer annotation;  \u00a0\u00a0\u00a0 public DependsOnContainerSetterBFPP(AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.annotation = annotation; \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 registerContainer(beanFactory); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setDependsOn(beanFactory, annotation); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 #{@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 private void registerContainer(ConfigurableListableBeanFactory beanFactory) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 registry.registerBeanDefinition(decapitalize(PostgresContainer.class.getSimpleName()), \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BeanDefinitionBuilder.genericBeanDefinition(PostgresContainer.class).getBeanDefinition()); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0 \u00a0\u00a0\u00a0* \u0417\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441 {@code annotation.beanToSubscribeOnEnvironmentSetter} \u00a0\u00a0\u00a0\u00a0 * \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 {@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 private void setDependsOn(ConfigurableListableBeanFactory beanFactory, AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0beanFactory.getBeanDefinition(geBeanWhoNeedsToDepend(annotation)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .setDependsOn(decapitalize(PostgresContainer.class.getSimpleName()));  \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * @return \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 {@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 * \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u0438\u0437 {@param annotation.beanNameThatNeedsToDependOnContainer} \u00a0\u00a0\u00a0\u00a0 * \u043b\u0438\u0431\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 {@param annotation.beanClassNameThatNeedsToDependOnContainer} \u00a0\u00a0\u00a0\u00a0 * \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u0438\u043d\u0433\u0443 \u0438 \u043f\u043e\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0431\u0443\u043a\u0432\u0430 \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 private String geBeanWhoNeedsToDepend(AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String beanToSubscribe = annotation.beanNameThatNeedsToDependOnContainer(); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (!beanToSubscribe.isEmpty()) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return beanToSubscribe; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Class&lt;?> beanClassToSubscribe = annotation.beanClassNameThatNeedsToDependOnContainer(); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (beanClassToSubscribe != Void.class) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return decapitalize(beanClassToSubscribe.getSimpleName()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 throw new RuntimeException(); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u0439, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b\u0430\u0441\u044c \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e      * \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public int getOrder() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return 0; \u00a0\u00a0\u00a0 } }<\/code><\/pre>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0414\u0430\u043b\u0435\u0435, \u0442.\u043a. \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0443 \u043d\u0430\u0441 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u2013 \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043b \u043d\u0430\u0448\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0438 \u0434\u0435\u043b\u0430\u043b \u0432\u0441\u044e \u043d\u0443\u0436\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e. \u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 (ContextCustomizerFactory -> ContextCustomizer). <br \/> \u0421\u043e\u0437\u0434\u0430\u0451\u043c ContextCustomizerFactory, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0447\u0438\u0442\u0430\u0435\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u043d\u0430 \u0441\u043b\u0435\u0434. \u0428\u0430\u0433\u0435)<\/p>\n<pre><code class=\"java\">public class ContainerContextCustomizerFactory implements ContextCustomizerFactory {  \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public ContextCustomizer createContextCustomizer(       Class&lt;?> testClass,       List&lt;ContextConfigurationAttributes> configAttributes     ) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AutoConfigurePostgresContainer annotation = testClass.getAnnotation(AutoConfigurePostgresContainer.class); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return new ContainerContextCustomizer(annotation); \u00a0\u00a0\u00a0 }  }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 META-INF\/spring.factories<\/p>\n<pre><code class=\"java\">org.springframework.test.context.ContextCustomizerFactory=\\ \u00a0 \u043f\u0443\u0442\u044c.\u043a.\u043a\u043b\u0430\u0441\u0441\u0443.ContainerContextCustomizerFactory<\/code><\/pre>\n<p>6.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u0412 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c <abbr title=\"BeanFactoryPostProcessor\" type=\"abbr\">BFPP <\/abbr>. <\/p>\n<pre><code class=\"java\">public class ContainerContextCustomizer implements ContextCustomizer {  \u00a0\u00a0\u00a0 private final AutoConfigurePostgresContainer annotation; \u00a0\u00a0\u00a0 public ContainerContextCustomizer(AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.annotation = annotation; \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public void customizeContext(       ConfigurableApplicationContext context,        MergedContextConfiguration mergedConfig     ) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 context.addBeanFactoryPostProcessor(new DependsOnContainerSetterBFPP(annotation)); \u00a0\u00a0\u00a0 }  }<\/code><\/pre>\n<p>7.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442<\/p>\n<pre><code class=\"java\">@SpringBootTest @AutoConfigurePostgresContainer(beanClassNameThatNeedsToDependOnContainer = DataSource.class) class DatabaseTest {      @Autowired     private PostgresContainer postgresContainer;      @Autowired     private MyRepository repository;      @Test     void testConnect() {         assertTrue(postgresContainer.getPostgreSQLContainer().isRunning());     }      @Test     void testRepo() {         MyEntity testEntity = new MyEntity().setName(\"testName\");         repository.save(testEntity);          List&lt;MyEntity> all = repository.findAll();         assertThat(testEntity).isEqualTo(all.get(0));     }  }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0432\u0441\u0451 \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><a class=\"anchor\" name=\"%D0%97%D0%B0%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\" id=\"\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\"><\/a><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 junit \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u0441\u0442\u0430\u0445, \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e.<\/p>\n<p>\u0411\u044b\u043b\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e:<\/p>\n<ol>\n<li>\n<p>\u041a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 ContextCustomizer<\/p>\n<\/li>\n<li>\n<p>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 BeanDefinition\u2019\u0430\u043c\u0438 \u043d\u0430 \u0440\u0430\u043d\u043d\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0441 \u044d\u0442\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u0443\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u0438 \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b \u0441 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p><a class=\"anchor\" name=\"%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D0%B8\" id=\"\u0421\u0441\u044b\u043b\u043a\u0438\"><\/a><\/p>\n<p><a href=\"https:\/\/www.testcontainers.org\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0442\u0435\u0441\u0442\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/haulmont\/blog\/454970\/\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot \u0438 Testcontainers<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/480106\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437 Oracle DB \u0434\u043b\u044f Testcontainers<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/514270\/\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 SpringBoot \u0441 TestContainers-\u0441\u0442\u0430\u0440\u0442\u0435\u0440\u043e\u043c<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/561520\/\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u0437\u043e\u0440 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Spring Boot<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/haulmont\/blog\/454970\/\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot \u0438 Testcontainers<\/a><\/p>\n<p><a href=\"https:\/\/gitlab.com\/fcontests\/habr-java-month\/test-containers-with-bean\/-\/tree\/master\/\" rel=\"noopener noreferrer nofollow\">\u041c\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c spring bean testcontainer&#8217;\u043e\u043c <\/a>\u00a0<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/681232\/\"> https:\/\/habr.com\/ru\/post\/681232\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<ol>\n<li>\n<p><a href=\"#%D0%92%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%A2%D0%B5%D0%BE%D1%80%D0%B8%D1%8F\" rel=\"noopener noreferrer nofollow\">\u0422\u0435\u043e\u0440\u0438\u044f<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%97%D0%B0%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D0%B8\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0438<\/a><\/p>\n<\/li>\n<\/ol>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p><a class=\"anchor\" name=\"%D0%92%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5\" id=\"\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435\">\u043d\u0438\u0435&#187;><\/a><\/p>\n<p>TestContainers \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043e\u0449\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/www.testcontainers.org\/\" rel=\"noopener noreferrer nofollow\">\u043d\u0430 \u043e\u0444 \u0441\u0430\u0439\u0442\u0435<\/a>, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/company\/jugru\/blog\/343298\/\" rel=\"noopener noreferrer nofollow\">\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440\u0435<\/a>. <\/p>\n<p>\u0422\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 junit4 (\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 <a href=\"https:\/\/habr.com\/ru\/company\/haulmont\/blog\/454970\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>, <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/514270\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>), \u0430 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u0447\u0435\u0440\u0435\u0437 junit5 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c DynamicPropertySource (\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/habr.com\/ru\/post\/561520\/\" rel=\"noopener noreferrer nofollow\">\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>) \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b, \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439. <\/p>\n<p>\u0422\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0430\u0437\u044b + \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u0438 \u0442.\u0434., \u0432 \u043e\u0431\u0449\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <u>\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432<\/u>, <u>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c properties<\/u> \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<p>\u0418 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c spring-beans \u2013 dependsOn.<\/p>\n<h2>\u0422\u0435\u043e\u0440\u0438\u044f<\/h2>\n<p><a class=\"anchor\" name=\"%D0%A2%D0%B5%D0%BE%D1%80%D0%B8%D1%8F\" id=\"\u0422\u0435\u043e\u0440\u0438\u044f\">\u0438\u044f&#187;><\/a><\/p>\n<p>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 + \u0442\u0435\u0441\u0442\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 + \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<p>Spring \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u042d\u0442\u0438\u043c \u043c\u044b \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b:<\/p>\n<ol>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c Bean \u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u00ab.properties\u00bb \u0444\u0430\u0439\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u0414\u041e \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u043d\u0451\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u044d\u0442\u043e\u0439 \u0441\u0430\u043c\u043e\u0439 \u0411\u0414<\/p>\n<\/li>\n<li>\n<p>\u0418 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c BeanFactoryPostProcessor (\u043a\u0430\u043a \u0434\u0430\u043d\u044c \u0443\u0432\u0430\u0436\u0435\u043d\u0438\u044f \u0415\u0432\u0433\u0435\u043d\u0438\u044e \u0411\u043e\u0440\u0438\u0441\u043e\u0432\u0443 \ud83d\ude09 ), \u0442.\u043a. \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <abbr title=\"BeanFactoryPostProcessor\" type=\"abbr\">BFPP <\/abbr>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 BeanDefinition\u2019\u0430\u043c\u0438 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e \u043d\u0438\u043c \u043d\u0430\u0447\u043d\u0443\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c\u0441\u044f \u0431\u0438\u043d\u044b. \u042d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043a\u0430\u043a \u0440\u0430\u0437 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432.<\/p>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h2>\n<p><a class=\"anchor\" name=\"%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D0%BA%D0%B0\" id=\"\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\">\u0438\u043a\u0430&#187;><\/a><\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0431\u0438\u043d \u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c<\/p>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0442\u043e \u0437\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d: \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c image, \u043b\u043e\u0433\u0438\u043d, \u043f\u0430\u0440\u043e\u043b\u044c, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0440\u0442 (\u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0434\u0435\u0431\u0430\u0433\u0435)<\/p>\n<pre><code class=\"java\">public class PostgresContainer {  \u00a0\u00a0\u00a0 private final PostgreSQLContainer&lt;?> postgreSQLContainer;  \u00a0\u00a0\u00a0 public PostgresContainer() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer = new PostgreSQLContainer&lt;>(DockerImageName.parse(\"postgres:14.3\"))3\")) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withDatabaseName(\"postgres\") \u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.withUsername(\"postgres\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withPassword(\"example\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withExposedPorts(5432) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; \u00a0\u00a0\u00a0 } }<\/code><\/pre>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0432 PostConstruct.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430. <\/p>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u0441\u0442\u0430 \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441<\/p>\n<pre><code class=\"java\">public class PostgresContainer {  \u00a0\u00a0\u00a0 private final PostgreSQLContainer&lt;?> postgreSQLContainer;  \u00a0\u00a0\u00a0 public PostgresContainer() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer = new PostgreSQLContainer&lt;>(DockerImageName.parse(\"postgres:14.3\")) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withDatabaseName(\"postgres\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withUsername(\"postgres\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withPassword(\"example\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .withExposedPorts(5432) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @PostConstruct \u00a0\u00a0\u00a0 public void start() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer.start();  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.setProperty(\"spring.datasource.url\", postgreSQLContainer.getJdbcUrl()); \u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0System.setProperty(\"spring.datasource.username\", postgreSQLContainer.getUsername()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.setProperty(\"spring.datasource.password\", postgreSQLContainer.getPassword()); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @PreDestroy \u00a0\u00a0\u00a0 public void stop() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postgreSQLContainer.stop(); \u00a0\u00a0\u00a0 } }<\/code><\/pre>\n<p>\u00a0<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u043b \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u0435 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e \u0431\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u0438\u043d\u043e\u0432. <\/p>\n<pre><code class=\"java\">@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface AutoConfigurePostgresContainer {  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430, \u0432 BeanDefinition \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430 #{@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 String beanNameThatNeedsToDependOnContainer() default \"\";  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u041a\u043b\u0430\u0441\u0441 \u0431\u0438\u043d\u0430, \u0432 BeanDefinition \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430 #{@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 Class&lt;?> beanClassNameThatNeedsToDependOnContainer() default Void.class;  }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 \u0441 \u0441\u0430\u043c\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c (\u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043a\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432). \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 \u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0430\u0440\u0442\u0430 \u0431\u0438\u043d\u043e\u0432. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438 \u0442.\u043f.<\/p>\n<p>4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c <abbr title=\"BeanFactoryPostProcessor\" type=\"abbr\">BFPP <\/abbr>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439<\/p>\n<pre><code class=\"java\">public class DependsOnContainerSetterBFPP implements BeanFactoryPostProcessor, Ordered {  \u00a0\u00a0\u00a0 private final AutoConfigurePostgresContainer annotation;  \u00a0\u00a0\u00a0 public DependsOnContainerSetterBFPP(AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.annotation = annotation; \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 registerContainer(beanFactory); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setDependsOn(beanFactory, annotation); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 #{@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 private void registerContainer(ConfigurableListableBeanFactory beanFactory) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 registry.registerBeanDefinition(decapitalize(PostgresContainer.class.getSimpleName()), \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BeanDefinitionBuilder.genericBeanDefinition(PostgresContainer.class).getBeanDefinition()); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0 \u00a0\u00a0\u00a0* \u0417\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441 {@code annotation.beanToSubscribeOnEnvironmentSetter} \u00a0\u00a0\u00a0\u00a0 * \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 {@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 private void setDependsOn(ConfigurableListableBeanFactory beanFactory, AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0beanFactory.getBeanDefinition(geBeanWhoNeedsToDepend(annotation)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .setDependsOn(decapitalize(PostgresContainer.class.getSimpleName()));  \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * @return \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 {@link PostgresContainer} \u00a0\u00a0\u00a0\u00a0 * \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u0438\u0437 {@param annotation.beanNameThatNeedsToDependOnContainer} \u00a0\u00a0\u00a0\u00a0 * \u043b\u0438\u0431\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 {@param annotation.beanClassNameThatNeedsToDependOnContainer} \u00a0\u00a0\u00a0\u00a0 * \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u0438\u043d\u0433\u0443 \u0438 \u043f\u043e\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0431\u0443\u043a\u0432\u0430 \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 private String geBeanWhoNeedsToDepend(AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String beanToSubscribe = annotation.beanNameThatNeedsToDependOnContainer(); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (!beanToSubscribe.isEmpty()) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return beanToSubscribe; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Class&lt;?> beanClassToSubscribe = annotation.beanClassNameThatNeedsToDependOnContainer(); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (beanClassToSubscribe != Void.class) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return decapitalize(beanClassToSubscribe.getSimpleName()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 throw new RuntimeException(); \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 \/** \u00a0\u00a0\u00a0\u00a0 * \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u0439, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b\u0430\u0441\u044c \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e      * \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u00a0\u00a0\u00a0\u00a0 *\/ \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public int getOrder() { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return 0; \u00a0\u00a0\u00a0 } }<\/code><\/pre>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0414\u0430\u043b\u0435\u0435, \u0442.\u043a. \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0443 \u043d\u0430\u0441 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u2013 \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043b \u043d\u0430\u0448\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0438 \u0434\u0435\u043b\u0430\u043b \u0432\u0441\u044e \u043d\u0443\u0436\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e. \u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 (ContextCustomizerFactory -> ContextCustomizer). <br \/> \u0421\u043e\u0437\u0434\u0430\u0451\u043c ContextCustomizerFactory, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0447\u0438\u0442\u0430\u0435\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u043d\u0430 \u0441\u043b\u0435\u0434. \u0428\u0430\u0433\u0435)<\/p>\n<pre><code class=\"java\">public class ContainerContextCustomizerFactory implements ContextCustomizerFactory {  \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public ContextCustomizer createContextCustomizer(       Class&lt;?> testClass,       List&lt;ContextConfigurationAttributes> configAttributes     ) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AutoConfigurePostgresContainer annotation = testClass.getAnnotation(AutoConfigurePostgresContainer.class); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return new ContainerContextCustomizer(annotation); \u00a0\u00a0\u00a0 }  }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 META-INF\/spring.factories<\/p>\n<pre><code class=\"java\">org.springframework.test.context.ContextCustomizerFactory=\\ \u00a0 \u043f\u0443\u0442\u044c.\u043a.\u043a\u043b\u0430\u0441\u0441\u0443.ContainerContextCustomizerFactory<\/code><\/pre>\n<p>6.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u0412 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c <abbr title=\"BeanFactoryPostProcessor\" type=\"abbr\">BFPP <\/abbr>. <\/p>\n<pre><code class=\"java\">public class ContainerContextCustomizer implements ContextCustomizer {  \u00a0\u00a0\u00a0 private final AutoConfigurePostgresContainer annotation; \u00a0\u00a0\u00a0 public ContainerContextCustomizer(AutoConfigurePostgresContainer annotation) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.annotation = annotation; \u00a0\u00a0\u00a0 }  \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public void customizeContext(       ConfigurableApplicationContext context,        MergedContextConfiguration mergedConfig     ) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 context.addBeanFactoryPostProcessor(new DependsOnContainerSetterBFPP(annotation)); \u00a0\u00a0\u00a0 }  }<\/code><\/pre>\n<p>7.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442<\/p>\n<pre><code class=\"java\">@SpringBootTest @AutoConfigurePostgresContainer(beanClassNameThatNeedsToDependOnContainer = DataSource.class) class DatabaseTest {      @Autowired     private PostgresContainer postgresContainer;      @Autowired     private MyRepository repository;      @Test     void testConnect() {         assertTrue(postgresContainer.getPostgreSQLContainer().isRunning());     }      @Test     void testRepo() {         MyEntity testEntity = new MyEntity().setName(\"testName\");         repository.save(testEntity);          List&lt;MyEntity> all = repository.findAll();         assertThat(testEntity).isEqualTo(all.get(0));     }  }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0432\u0441\u0451 \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><a class=\"anchor\" name=\"%D0%97%D0%B0%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\" id=\"\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\">\u0435\u043d\u0438\u0435&#187;><\/a><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 junit \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u0441\u0442\u0430\u0445, \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e.<\/p>\n<p>\u0411\u044b\u043b\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e:<\/p>\n<ol>\n<li>\n<p>\u041a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 ContextCustomizer<\/p>\n<\/li>\n<li>\n<p>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 BeanDefinition\u2019\u0430\u043c\u0438 \u043d\u0430 \u0440\u0430\u043d\u043d\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-336695","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336695"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336695\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}