{"id":83969,"date":"2018-11-28T10:00:20","date_gmt":"2018-11-28T08:00:20","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=83969"},"modified":"2018-11-27T12:10:39","modified_gmt":"2018-11-27T10:10:39","slug":"running-code-spring-boot-startup","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html","title":{"rendered":"Running code on Spring Boot startup"},"content":{"rendered":"<p>Spring Boot does a lot of configuration automatically for us but sooner or later you\u2019ll have to do some custom work. In this post, you will <b>learn how to hook into the application bootstrap lifecycle and execute code on Spring Boot startup<\/b>.<\/p>\n<p>So let\u2019s see what the framework has to offer.<ins><\/ins><\/p>\n<h2>1. Execute method on bean initialization<\/h2>\n<p>The simplest way to run some logic once the Spring starts your application is to execute the code as part of a chosen bean bootstrapping process.<\/p>\n<p>What you have to do?<\/p>\n<p>Just create a class, mark it as a Spring component, and put the app initialization code in a method with the <i>@PostConstruct<\/i> annotation. In theory, you could use a constructor instead of a separate method but it\u2019s a good practice to separate the object\u2019s construction from its real responsibility.<\/p>\n<pre class=\"brush:java\">@Component\r\nclass AppInitializator {\r\n\r\n    private static final Logger log = LoggerFactory.getLogger(AppInitializator.class);\r\n\r\n    @PostConstruct\r\n    private void init() {\r\n        log.info(\"AppInitializator initialization logic ...\");\r\n        \/\/ ...\r\n    }\r\n\r\n}<\/pre>\n<p>If you use the lazy initialization of the application context (e.g. to <a href=\"http:\/\/dolszewski.com\/spring\/faster-spring-boot-startup\/\">speed up Spring Boot startup<\/a>), the bean with initialization logic should be excluded from this mechanism. I\u2019ve described <a href=\"https:\/\/www.javacodegeeks.com\/2018\/03\/spring-lazy-annotation-use-cases.html\">how to create a bean eagerly with the @Lazy annotation when whole Spring context uses lazy loading<\/a>.<\/p>\n<p>You can also create a method with the <i>@PostConstruct<\/i> annotation inside your main Spring Boot application class. Don\u2019t forget that the main class is also a component managed by the framework.<\/p>\n<pre class=\"brush:java\">@SpringBootApplication\r\npublic class InitDemoApplication {\r\n\r\n    \/\/ ...\r\n\r\n    @PostConstruct\r\n    private void init() {\r\n        log.info(\"InitDemoApplication initialization logic ...\");\r\n        \/\/ ...\r\n    }\r\n\r\n}<\/pre>\n<p>But this solution feels like a workaround rather than a real solution. You can control the order in which the Spring framework creates application beans in a very limited way. If we want to run the initialization logic before all beans are created or even before the framework starts, we need to find something better.<\/p>\n<h2>2. Spring Boot startup hooks<\/h2>\n<p>The beauty of applications created with Spring Boot is that the only thing you need to run them is Java Runtime Environment and the command line interface. No external tools or application required. It runs just like a regular Java SE program.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>As every Java program, you start execution of such application in the static main method of your entry application class. That\u2019s the point in which you can hook into Spring Boot initialization process.<\/p>\n<h3>2.1. Creating Spring Boot hook<\/h3>\n<p>Start by changing the code in your main method to extract appending of startup hooks to a separate method. You should add Spring Boot hooks before the application is started.<\/p>\n<pre class=\"brush:java\">public static void main(String[] args) {\r\n    SpringApplication application = new SpringApplication(InitDemoApplication.class);\r\n    addInitHooks(application);\r\n    application.run(args);\r\n}\r\n\r\nstatic void addInitHooks(SpringApplication application) {\r\n    \/\/ TBD \u2026\r\n}<\/pre>\n<p>When a Spring Boot application starts, it publishes several events on individual steps of the bootstrap process. The API of the SpringApplication class exposes a method which we can use to add listeners for those events.<\/p>\n<p>Here\u2019s an example which runs a startup method on the event published before the Spring context starts creating your beans:<\/p>\n<pre class=\"brush:java\">static void addInitHooks(SpringApplication application) {\r\n   application.addListeners((ApplicationListener&lt;ApplicationEnvironmentPreparedEvent&gt;) event -&gt; {\r\n       String version = event.getEnvironment().getProperty(\"java.runtime.version\");\r\n       log.info(\"Running with Java {}\", version);\r\n   });\r\n}<\/pre>\n<h3>2.2. Event types<\/h3>\n<p>Depending on <a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/api\/org\/springframework\/boot\/context\/event\/SpringApplicationEvent.html\">the event type<\/a>, the object which Spring passes to the listener may give you access to several useful operations. In the previous example, we read some environment property but we could also modify it if needed.<\/p>\n<p>Here\u2019s the list of possible events sorted by the order in which events are published by Spring Boot on the startup:<\/p>\n<ul>\n<li>ApplicationStartingEvent<\/li>\n<li>ApplicationEnvironmentPreparedEvent<\/li>\n<li>ApplicationContextInitializedEvent<\/li>\n<li>ApplicationPreparedEvent<\/li>\n<li>ApplicationStartedEvent<\/li>\n<li>ApplicationReadyEvent<\/li>\n<\/ul>\n<p>I don\u2019t want to duplicate <a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/boot-features-spring-application.html#boot-features-application-events-and-listeners\">the documentation of events<\/a> so if you\u2019re interested in the description you should check it out. There is also <i>ApplicationFailedEvent<\/i> but it\u2019s only published when the framework fails to start your application.<\/p>\n<p>From my experience, <b>the most important event<\/b> is <a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/api\/org\/springframework\/boot\/context\/event\/ApplicationEnvironmentPreparedEvent.html\">ApplicationEnvironmentPreparedEvent<\/a>. At this moment of the Spring Boot startup, the beans aren\u2019t created yet but you can access the whole application configuration. Usually, that\u2019s the best moment to run some custom startup code.<\/p>\n<h2>3. Run code on startup without embedded Tomcat<\/h2>\n<p>Although Spring Boot designers created the framework with building fat JARs in mind, some developers still deploy Spring Boot applications to regular servlet containers like Tomcat. If that is the case for you, the solution from the previous paragraph won\u2019t work without an additional step.<\/p>\n<p>If you <a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/howto-traditional-deployment.html\">deploy your application as a regular WAR file<\/a>, you probably already have a custom implementation of the SpringBootServlerInitializator. You only have to slightly extend it and add your initialization hooks as a part of the application building process.<\/p>\n<p>You can easily reuse the <i>addInitHooks()<\/i> method we created in the main application class.<\/p>\n<pre class=\"brush:java\">public class InitDemoWarInitializer extends SpringBootServletInitializer {\r\n\r\n    @Override\r\n    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {\r\n        InitDemoApplication.addInitHooks(builder.application());\r\n        return builder.sources(InitDemoApplication.class);\r\n    }\r\n\r\n}<\/pre>\n<h2>Conclusion<\/h2>\n<p>In short, there are two main options to run code on Spring Boot startup. The simplest one is rather designed to initialize a particular bean. For more global cases, the framework has a dedicated solution to hook into its lifecycle using event listeners. We learned how to implement and set up such listeners.<\/p>\n<p>I hope you find the post useful. You can find the <a href=\"https:\/\/github.com\/danielolszewski\/blog\/tree\/master\/spring-boot-init-demo\">fully working demo<\/a> in my Github repository. I would be happy to see your comments about the use cases in which a custom hook was required. That should make interesting reading.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Daniel Olszewski, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/dolszewski.com\/spring\/running-code-on-spring-boot-startup\/\" target=\"_blank\" rel=\"noopener\">Running code on Spring Boot startup<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot does a lot of configuration automatically for us but sooner or later you\u2019ll have to do some custom work. In this post, you will learn how to hook into the application bootstrap lifecycle and execute code on Spring Boot startup. So let\u2019s see what the framework has to offer. 1. Execute method on &hellip;<\/p>\n","protected":false},"author":3861,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30,854],"class_list":["post-83969","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Running code on Spring Boot startup - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about Spring Boot startup? Check our article explaining how to hook into the application bootstrap and execute code on Spring startup.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running code on Spring Boot startup - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about Spring Boot startup? Check our article explaining how to hook into the application bootstrap and execute code on Spring startup.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-28T08:00:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Daniel Olszewski\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@daolszewski\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Olszewski\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html\"},\"author\":{\"name\":\"Daniel Olszewski\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/f2727a76059a91188524de49e1e397fb\"},\"headline\":\"Running code on Spring Boot startup\",\"datePublished\":\"2018-11-28T08:00:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html\"},\"wordCount\":843,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\",\"Spring Boot\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html\",\"name\":\"Running code on Spring Boot startup - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2018-11-28T08:00:20+00:00\",\"description\":\"Interested to learn about Spring Boot startup? Check our article explaining how to hook into the application bootstrap and execute code on Spring startup.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/running-code-spring-boot-startup.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Running code on Spring Boot startup\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/f2727a76059a91188524de49e1e397fb\",\"name\":\"Daniel Olszewski\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g\",\"caption\":\"Daniel Olszewski\"},\"description\":\"Daniel Olszewski is a software developer passionate about the JVM ecosystem and web development. He is an advocate of clean, maintainable, and well tested code\",\"sameAs\":[\"http:\\\/\\\/dolszewski.com\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/olszewskidaniel\\\/\",\"https:\\\/\\\/x.com\\\/daolszewski\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/daniel-olszewski\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running code on Spring Boot startup - Java Code Geeks","description":"Interested to learn about Spring Boot startup? Check our article explaining how to hook into the application bootstrap and execute code on Spring startup.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html","og_locale":"en_US","og_type":"article","og_title":"Running code on Spring Boot startup - Java Code Geeks","og_description":"Interested to learn about Spring Boot startup? Check our article explaining how to hook into the application bootstrap and execute code on Spring startup.","og_url":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-11-28T08:00:20+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Daniel Olszewski","twitter_card":"summary_large_image","twitter_creator":"@daolszewski","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Daniel Olszewski","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html"},"author":{"name":"Daniel Olszewski","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/f2727a76059a91188524de49e1e397fb"},"headline":"Running code on Spring Boot startup","datePublished":"2018-11-28T08:00:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html"},"wordCount":843,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring","Spring Boot"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html","url":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html","name":"Running code on Spring Boot startup - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2018-11-28T08:00:20+00:00","description":"Interested to learn about Spring Boot startup? Check our article explaining how to hook into the application bootstrap and execute code on Spring startup.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/running-code-spring-boot-startup.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Running code on Spring Boot startup"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/f2727a76059a91188524de49e1e397fb","name":"Daniel Olszewski","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g","caption":"Daniel Olszewski"},"description":"Daniel Olszewski is a software developer passionate about the JVM ecosystem and web development. He is an advocate of clean, maintainable, and well tested code","sameAs":["http:\/\/dolszewski.com","https:\/\/www.linkedin.com\/in\/olszewskidaniel\/","https:\/\/x.com\/daolszewski"],"url":"https:\/\/www.javacodegeeks.com\/author\/daniel-olszewski"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/83969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/3861"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=83969"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/83969\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=83969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=83969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=83969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}