{"id":1247,"date":"2015-06-25T10:31:27","date_gmt":"2015-06-25T14:31:27","guid":{"rendered":"http:\/\/springframework.guru\/?p=1247"},"modified":"2019-06-21T09:17:57","modified_gmt":"2019-06-21T13:17:57","slug":"spring-boot-web-application-part-2-using-thymeleaf","status":"publish","type":"post","link":"https:\/\/springframework.guru\/spring-boot-web-application-part-2-using-thymeleaf\/","title":{"rendered":"Spring Boot Web Application &#8211; Part 2 &#8211; Using ThymeLeaf"},"content":{"rendered":"<p>In the <a href=\"http:\/\/springframework.guru\/spring-boot-web-application-part-1-spring-initializr\/\">first part <\/a>of this tutorial series for building a web application using Spring Boot, we looked at creating our Spring project using the Spring Initializr. This handy tool gave us a Spring project to work with, jump starting our development effort by creating the project structure and Maven dependencies for us.<\/p>\n<p>In this post I am going to walk you through enabling rendering a webpage using Thymeleaf and Spring MVC.<\/p>\n<h3>Why Thymeleaf?<\/h3>\n<p>Traditionally, Spring MVC applications used Java Server Pages, or JSPs to generate html content. JSPs are a mature technology and has been around since the early days of Java. In terms of raw speed, JSPs are hard to beat too. But when you do not need the absolute raw speed of a JSP, you may want to consider alternatives to JSPs which help improve developer productivity.<\/p>\n<p>JSPs offer an HTML &#8216;like&#8217; syntax. Meaning its close, but not completely compatible with HTML. Thymeleaf on the other hand, aims to be a &#8220;Natural Template&#8221;. This means the Thymeleaf template file will open and display normally in a browser, while a JSP file does not.<\/p>\n<p>I also have selfish reasons for using Thymeleaf in this tutorial on Spring Boot. I&#8217;ve never used it, and I thought it looked\u00a0like a cool technology to try out.<\/p>\n<figure id=\"attachment_4223\" aria-describedby=\"caption-attachment-4223\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/bit.ly\/2yhpu6x\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4223 size-full\" src=\"http:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/ReactiveIsComing2NewSmall02.png\" alt=\"Spring Framework 5\" width=\"560\" height=\"292\" srcset=\"https:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/ReactiveIsComing2NewSmall02.png 560w, https:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/ReactiveIsComing2NewSmall02-300x156.png 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/a><figcaption id=\"caption-attachment-4223\" class=\"wp-caption-text\">Become a Spring Framework Guru! Click here to learn about my Spring Framework 5: Beginner to Guru online course!<\/figcaption><\/figure>\n<h1>Thymeleaf Configuration and Spring Boot<\/h1>\n<p>If you were using just Spring MVC, you would need to configure the Thymeleaf template engine for use. That&#8217;s not so when you&#8217;re using Spring Boot, because we&#8217;ve included the dependency <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">spring-boot-starter-thymeleaf <\/code>\u00a0in our Maven POM for the project, so Spring Boot will do some things automatically for us.<\/p>\n<p>By default, Spring Boot configures the Thymeleaf template engine to read template files from <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\/resources\/templates<\/code>\u00a0.<\/p>\n<p>Effectively, you as the developer just need to start making Thymeleaf templates and dropping them into\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\/resources\/templates<\/code>.<\/p>\n<h3>Thymeleaf Template<\/h3>\n<p>Let&#8217;s start with a very basic HTML file to show.<\/p>\n<h4>Thymeleaf Template &#8211; index.html<\/h4>\n<p>A few things I&#8217;d like to point out in the HTML:<\/p>\n<ul>\n<li>Line 1 &#8211; Is the standard declaration for HTML 5<\/li>\n<li>Line 2 &#8211; sets a XML Namespace for Thymeleaf. This is important as you start to use the Thymeleaf extensions.<\/li>\n<li>Line 6 &#8211; Defines the character set for the HTML file.<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"git\">&lt;!DOCTYPE html&gt;\r\n&lt;html xmlns:th=\"http:\/\/www.thymeleaf.org\"&gt;\r\n&lt;head lang=\"en\"&gt;\r\n\r\n    &lt;title&gt;Spring Framework Guru&lt;\/title&gt;\r\n    &lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=UTF-8\"\/&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h1&gt;Hello&lt;\/h1&gt;\r\n\r\n&lt;h2&gt;Fellow Spring Framework Gurus!!!&lt;\/h2&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h3>Spring MVC Controller<\/h3>\n<p>The next step we need to take care of is creating a Spring MVC controller. Because we&#8217;ve included the dependency <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">spring-boot-starter-web<\/code>, Spring Boot automatically configured Spring MVC for us. We also get an embedded instance of Tomcat to run our application in too. This may sound simple, but it does take care of a lot of setup tasks that we would normally need to do if we were using Spring MVC without Spring Boot.<\/p>\n<p>With using Spring Boot, we only need to define our controller class, nothing else. Like other things, Spring Boot sets up sensible defaults for us.<\/p>\n<h4>IndexController.java<\/h4>\n<p>At this point, we just need a very simple controller. We want to map the web root path <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\"\/\"<\/code> to the index template. A common convention used in Spring MVC is to return the string name of the template file, less the file extension. Thus to show the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">index.html<\/code> file we defined above, our controller method needs to return the string <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\"index\"<\/code><\/p>\n<p>On Line 6, I&#8217;ve\u00a0used the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">@Controller<\/code>\u00a0 annotation to make this class a Spring component and a Spring MVC controller. On line 9, you can see that I annotated the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">index()<\/code>\u00a0 method with a <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">@RequestMapping<\/code>\u00a0 annotation. By doing this, I&#8217;ve configured the root path to this controller method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">package guru.springframework.controllers;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\n\r\n@Controller\r\npublic class IndexController {\r\n    @RequestMapping(\"\/\")\r\n    String index(){\r\n        return \"index\";\r\n    }\r\n}<\/pre>\n<h3>Running the Example<\/h3>\n<p>If you&#8217;re using IntelliJ, you can go into the class <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">SpringBootWebApplication<\/code>\u00a0 and right click on the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">main()<\/code>\u00a0 method, then click on run. This will run the Spring Boot application. Spring Boot will startup an embedded instance of Tomcat and deploy our application to it.<\/p>\n<p>BUT &#8211; if you navigate to <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">http:\/\/localhost:8080<\/code> via your browser, the port Tomcat is listening on, you will see this:<\/p>\n<p><a href=\"http:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-12-at-7.41.47-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1256\" src=\"http:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-12-at-7.41.47-AM.png\" alt=\"Basic Auth via Spring Security\" width=\"397\" height=\"226\" srcset=\"https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-12-at-7.41.47-AM.png 397w, https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-12-at-7.41.47-AM-300x171.png 300w\" sizes=\"(max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<p>So, what&#8217;s happening here? Because we added Spring Security into our build, Spring Boot has configured Spring Security for our use. The default behavior is to require basic auth for all endpoints. This is a good approach to secure everything by default, but it can trip you up if you&#8217;re not accustomed to working with Spring Security.<\/p>\n<h3>Spring Security Configuration<\/h3>\n<p>What we need to do, is tell Spring Security to allow all requests access to the root path. I&#8217;ll be covering Spring Security\u00a0in additional detail in a future post,\u00a0 but for now, we need to add a Spring Configuration class to allow us to configure Spring Security.<\/p>\n<h4>SecurityConfiguration.java<\/h4>\n<p>To accommodate the Spring Security configuration, I created a new package and added the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">SecurityConfiguration<\/code>\u00a0 class. By annotating the class with the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">@Configuration<\/code>\u00a0 annotation, I&#8217;m telling Spring\u00a0this is a configuration class. When doing Java configuration for Spring Security, you need to extend\u00a0the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">WebSecurityConfigurerAdapater<\/code>\u00a0 class and override the configure method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">package guru.springframework.configuration;\r\n\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.security.config.annotation.web.builders.HttpSecurity;\r\nimport org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;\r\n\r\n@Configuration\r\npublic class SecurityConfiguration extends WebSecurityConfigurerAdapter {\r\n\r\n    @Override\r\n    protected void configure(HttpSecurity httpSecurity) throws Exception {\r\n        httpSecurity.authorizeRequests().antMatchers(\"\/\").permitAll();\r\n    }\r\n\r\n}<\/pre>\n<h3>Spring Boot and Package Scans<\/h3>\n<p>One quick note I want to call out here, the controller and configuration classes I&#8217;ve just defined are annotated Spring Components. Spring will only pick these up when their respective package is included in a component scan. A default behavior of Spring Boot when using the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">@SpringBootApplication<\/code> annotation is to perform a package scan on its package (and all sub packages). Because my Spring Boot application resides in the package <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">guru.springframework<\/code>, the annotated Spring Components in the child packages are automatically found by Spring. If they were in a different package tree, I would need to explicitly tell Spring Boot to scan that package. This is important to know, and is something that could easily trip up a beginner with Spring Boot.<\/p>\n<h4>Example Web Page:<\/h4>\n<p>At this point in building our Spring Boot web application, we have not applied any styling to our Thymeleaf template file. Its pure simple, unstyled HTML.<\/p>\n<p><a href=\"http:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.35.55-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1264\" src=\"http:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.35.55-PM.png\" alt=\"unstyled spring boot web page\" width=\"1210\" height=\"257\" srcset=\"https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.35.55-PM.png 1210w, https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.35.55-PM-300x64.png 300w, https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.35.55-PM-1024x217.png 1024w\" sizes=\"(max-width: 1210px) 100vw, 1210px\" \/><\/a><\/p>\n<h2>Managing Web Resources Under Spring Boot<\/h2>\n<p>At this point our Spring Boot Web application is working, in the sense, it generates some HTML. But that&#8217;s not very realistic for today&#8217;s web applications. Any modern web application is going to have some web resources to manage. Web resources typically include:<\/p>\n<ul>\n<li>CSS files.<\/li>\n<li>Javascript assets<\/li>\n<li>Images<\/li>\n<\/ul>\n<p>Right now, our web page is very boring. Let&#8217;s dress it up using Bootstrap CSS and JQuery.<\/p>\n<h3>Static Resources with Spring Boot<\/h3>\n<p>Spring Boot will automatically serve static resources from the path <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\/resources\/static<\/code>. By a generally accepted convention, you will typically put CSS files in <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\/resources\/static\/css<\/code>, Javascript files in <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\/resources\/static\/js<\/code>, and images in <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">resources\/static\/images<\/code>. You could name the directories after <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\/resources\/static\/<\/code> whatever you wish, this is just a convention you will likely see used and it helps you organize the static resources.<\/p>\n<p>I like to add a CSS file for any overrides and customization I&#8217;ll need. I&#8217;m going to add an empty CSS file into <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">\/resources\/static\/css<\/code> and then add it to the Thymeleaf template as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\">    &lt;link href=\"..\/static\/css\/guru.css\"\r\n          th:href=\"@{css\/guru.css}\" rel=\"stylesheet\" media=\"screen\"\/&gt;<\/pre>\n<p>Notice how the link tag has two href attributes? The first one in normal HTML will be used by the browser when the template is read from the file system. The second with the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">th<\/code> namespace is used by Thymeleaf when the template is rendered via Spring Boot. In this case a <a href=\"http:\/\/springframework.guru\/introduction-spring-expression-language-spel\/\">SPeL<\/a> expression is being used to resolve the path of the static asset under Spring Boot, and this will be used as the path when the template is rendered by Spring Boot for the browser via a request through Tomcat.<\/p>\n<p>This is what is meant when Thymeleaf is called a natural template engine. In this case, the CSS file is found for the HTML file via the relative path in the file system, then again when it&#8217;s deployed using a SPeL notation.<\/p>\n<h3>Spring Boot and WebJars<\/h3>\n<p>More than once I&#8217;ve copied all the files for Bootstrap CSS or JQuery into a resources folder, and then managed the lifecycle of their versions. This can be a manual and tedious process. WebJars is a very cool concept which packages web assets into a JAR file for your use. The JAR s are available in public Maven repositories, making them build assets you can easily include in your project. (Did you know JAR files are just zip files, with the extension changed to JAR?)<\/p>\n<p>Spring Boot supports WebJars out of the box. We just need to include the dependency in our Maven POM file for the project, then add it to our Thymeleaf template file.<\/p>\n<p>We can declare the WebJar dependencies for Bootstrap CSS and JQuery by adding the following lines to our Maven POM file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\">\t\t&lt;!--WebJars--&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.webjars&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;bootstrap&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;3.3.4&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.webjars&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;jquery&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;2.1.4&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;<\/pre>\n<p>Now we can add the Bootstrap CSS and JQuery dependencies to our <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">index.html<\/code> file as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\">    &lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=UTF-8\"\/&gt;\r\n\r\n    &lt;link href=\"http:\/\/cdn.jsdelivr.net\/webjars\/bootstrap\/3.3.4\/css\/bootstrap.min.css\"\r\n          th:href=\"@{\/webjars\/bootstrap\/3.3.4\/css\/bootstrap.min.css}\"\r\n          rel=\"stylesheet\" media=\"screen\" \/&gt;\r\n\r\n    &lt;script src=\"http:\/\/cdn.jsdelivr.net\/webjars\/jquery\/2.1.4\/jquery.min.js\"\r\n            th:src=\"@{\/webjars\/jquery\/2.1.4\/jquery.min.js}\"&gt;&lt;\/script&gt;\r\n\r\n    &lt;link href=\"..\/static\/css\/guru.css\"\r\n          th:href=\"@{css\/guru.css}\" rel=\"stylesheet\" media=\"screen\"\/&gt;<\/pre>\n<p>Note: In this example I&#8217;m using a public CDN for the Bootstrap CSS and JQuery assets. By doing this I can preserve the natural templating of the Thymeleaf template file.<\/p>\n<figure id=\"attachment_4223\" aria-describedby=\"caption-attachment-4223\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/bit.ly\/2yhpu6x\" target=\"_blank\" rel=\"attachment wp-att-2119 noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4223 size-full\" src=\"http:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/ReactiveIsComing2NewSmall02.png\" alt=\"Spring Framework 5\" width=\"560\" height=\"292\" srcset=\"https:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/ReactiveIsComing2NewSmall02.png 560w, https:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/ReactiveIsComing2NewSmall02-300x156.png 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/a><figcaption id=\"caption-attachment-4223\" class=\"wp-caption-text\">Click here to learn more about my online course Spring Framework 5: Beginner to Guru!<\/figcaption><\/figure>\n<h2>Styling Our Example<\/h2>\n<p>Now that we have the Bootstrap CSS and JQuery resources loading with our Spring Boot web application, lets add a little Bootstrap styling to our <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">index.html<\/code> file.<\/p>\n<h4>index.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">&lt;!DOCTYPE html&gt;\r\n&lt;html xmlns:th=\"http:\/\/www.thymeleaf.org\"&gt;\r\n&lt;head lang=\"en\"&gt;\r\n\r\n    &lt;title&gt;Spring Framework Guru&lt;\/title&gt;\r\n    &lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=UTF-8\"\/&gt;\r\n\r\n    &lt;link href=\"http:\/\/cdn.jsdelivr.net\/webjars\/bootstrap\/3.3.4\/css\/bootstrap.min.css\"\r\n          th:href=\"@{\/webjars\/bootstrap\/3.3.4\/css\/bootstrap.min.css}\"\r\n          rel=\"stylesheet\" media=\"screen\" \/&gt;\r\n\r\n    &lt;script src=\"http:\/\/cdn.jsdelivr.net\/webjars\/jquery\/2.1.4\/jquery.min.js\"\r\n            th:src=\"@{\/webjars\/jquery\/2.1.4\/jquery.min.js}\"&gt;&lt;\/script&gt;\r\n\r\n    &lt;link href=\"..\/static\/css\/guru.css\"\r\n          th:href=\"@{css\/guru.css}\" rel=\"stylesheet\" media=\"screen\"\/&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div class=\"container\"&gt;\r\n    &lt;div class=\"jumbotron\"&gt;\r\n        &lt;img src=\"..\/static\/images\/FBcover1200x628.png\" width=\"1000\"\r\n             th:src=\"@{images\/FBcover1200x628.png}\"\/&gt;\r\n        &lt;h1&gt;Hello&lt;\/h1&gt;\r\n\r\n        &lt;h2&gt;Fellow Spring Framework Gurus!!!&lt;\/h2&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h4>Example web page:<\/h4>\n<p><a href=\"http:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.34.41-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1263\" src=\"http:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.34.41-PM.png\" alt=\"spring boot web page\" width=\"1213\" height=\"873\" srcset=\"https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.34.41-PM.png 1213w, https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.34.41-PM-300x216.png 300w, https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.34.41-PM-1024x737.png 1024w, https:\/\/springframework.guru\/wp-content\/uploads\/2015\/06\/Screen-Shot-2015-06-16-at-6.34.41-PM-180x129.png 180w\" sizes=\"(max-width: 1213px) 100vw, 1213px\" \/><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>At this point in this tutorial series on building a Spring Boot web application using Spring Boot, we&#8217;ve shown you how to create a basic project using the Spring Initializr and setup support for Thymeleaf. You can see how Spring Boot has made some common sense choices for us, like configuring the Thymeleaf template engine for use with Spring MVC, defaulting the locations for static resources, and providing out of the box support for WebJars.<\/p>\n<p>In our <a href=\"http:\/\/springframework.guru\/spring-boot-web-application-part-3-spring-data-jpa\/\">next post on Spring Boot<\/a>, we will take a look at setting up the persistence layer with Spring Boot, H2 and Spring Data JPA.<\/p>\n<h2>Get The\u00a0Code<\/h2>\n<p>I&#8217;ve committed the source code for this post to GitHub. It is a Maven project which you can download and build. If you wish to learn more about the Spring Framework, I have a free introduction to Spring tutorial. You can sign up for this tutorial in the section below.<\/p>\n<p>The source code for this post is available on GitHub. You can download it <a title=\"Spring Boot Web Application\" href=\"https:\/\/github.com\/springframeworkguru\/springbootwebapp\/tree\/part2\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<h2>Video<\/h2>\n<p>I\u00a0went through the content of this post on YouTube video. You can check it out below.<\/p>\n<div class=\"lyte-wrapper\" style=\"width:640px;max-width:100%;margin:5px auto;\"><div class=\"lyMe\" id=\"WYL_NN_hSBEYBVE\"><div id=\"lyte_NN_hSBEYBVE\" data-src=\"\/\/i.ytimg.com\/vi\/NN_hSBEYBVE\/hqdefault.jpg\" class=\"pL\"><div class=\"tC\"><div class=\"tT\"><\/div><\/div><div class=\"play\"><\/div><div class=\"ctrl\"><div class=\"Lctrl\"><\/div><div class=\"Rctrl\"><\/div><\/div><\/div><noscript><a href=\"https:\/\/youtu.be\/NN_hSBEYBVE\" rel=\"nofollow\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.ytimg.com\/vi\/NN_hSBEYBVE\/0.jpg\" alt=\"\" width=\"640\" height=\"340\" \/><br \/>Watch this video on YouTube<\/a><\/noscript><\/div><\/div><div class=\"lL\" style=\"max-width:100%;width:640px;margin:5px auto;\"><\/div>\n<p><span style=\"border-radius: 2px; text-indent: 20px; width: auto; padding: 0px 4px 0px 0px; text-align: center; font: bold 11px\/20px 'Helvetica Neue',Helvetica,sans-serif; color: #ffffff; background: #bd081c no-repeat scroll 3px 50% \/ 14px 14px; position: absolute; opacity: 1; z-index: 8675309; display: none; cursor: pointer;\">Save<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the first part of this tutorial series for building a web application using Spring Boot, we looked at creating our Spring project using the Spring Initializr. This handy tool gave us a Spring project to work with, jump starting our development effort by creating the project structure and Maven dependencies for us. In this [&hellip;]<a href=\"https:\/\/springframework.guru\/spring-boot-web-application-part-2-using-thymeleaf\/\" class=\"df-link-excerpt\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":4575,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Spring Boot Web Application - Part 2 - Using ThymeLeaf https:\/\/wp.me\/p5BZrZ-k7 #Spring #springboot","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[104],"tags":[29,115],"class_list":["post-1247","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot","tag-spring-boot","tag-thymeleaf"],"jetpack_publicize_connections":[],"aioseo_notices":[],"modified_by":"Simanta","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/NewBannerBOOTSWeb.jpg","jetpack_shortlink":"https:\/\/wp.me\/p5BZrZ-k7","_links":{"self":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts\/1247"}],"collection":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/comments?post=1247"}],"version-history":[{"count":12,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts\/1247\/revisions"}],"predecessor-version":[{"id":3136,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts\/1247\/revisions\/3136"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/media\/4575"}],"wp:attachment":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/media?parent=1247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/categories?post=1247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/tags?post=1247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}