Skip to content

Commit

Permalink
Merge pull request #13 from kolorobot/12-spring-boot-2
Browse files Browse the repository at this point in the history
Updated to Spring Boot 2

- Most of the deps updated
- Java 11 as default
- Layout and templates files improved / cleaned
- Docs improved
- Thymeleaf security dialect added
- Cleaned up a bit pom.xml

Known issues: Selenium config does not work, the test commented out.
  • Loading branch information
kolorobot authored May 15, 2021
2 parents fb897a1 + 5eb3b58 commit b44604f
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 327 deletions.
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
Spring Boot and Thymeleaf with Maven
====================================

- Spring Boot with Maven and Spring IO Platform for dependency management
- Spring Boot 2
- Web application (WAR) packaging as well as self-contained JAR
- Thymeleaf with Java 8 Time (Java8TimeDialect)
- Thymeleaf with Java 8 Time Dialect and Layout Dialect
- WebJars
- Selenium configuration included
- Maven Wrapper included

Prerequisites
-------------

- JDK 8 and JAVA_HOME environment variable set
- JDK 11 and JAVA_HOME environment variable set

Building the project
--------------------

Clone the repository:

> git clone https://github.com/kolorobot/spring-boot-thymeleaf
git clone https://github.com/kolorobot/spring-boot-thymeleaf

Navigate to the newly created folder:

> cd spring-boot-thymeleaf
cd spring-boot-thymeleaf

Run the project with:

> mvnw clean spring-boot:run
./mvnw clean spring-boot:run

To package the project run:

> mvnw clean package
./mvnw clean package

Open the application
--------------------

Application will be running on http://localhost:8080

To login enter `user` and `demo`


Known issues
------------

- Text templates example does not work
- Selenium configuration does not work

Referenced articles:
--------------------
Expand Down
Empty file modified mvnw
100644 → 100755
Empty file.
63 changes: 35 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,44 @@

<groupId>pl.codeleak.demos.sbt</groupId>
<artifactId>spring-boot-thymeleaf</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>2.0.0</version>
<name>spring-boot-thymeleaf</name>
<packaging>war</packaging>

<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>

<!-- Inherit defaults from Spring Boot -->
<!-- With this starter it is easier to override versions of libraries -->

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<version>2.4.5</version>
</parent>

<!-- Spring IO Platform for dependency management -->
<!-- If you are using platform-bom, disable spring-boot-starter-parent -->
<!--<dependencyManagement>-->
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>io.spring.platform</groupId>-->
<!--<artifactId>platform-bom</artifactId>-->
<!--<version>2.0.8.RELEASE</version>-->
<!--<type>pom</type>-->
<!--<scope>import</scope>-->
<!--</dependency>-->
<!--</dependencies>-->
<!--</dependencyManagement>-->

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>

<!-- Overriding version of selected dependencies -->
<!-- Work when using spring-boot-starter-parent, not platform-bom -->
<thymeleaf.version>3.0.6.RELEASE</thymeleaf.version>
<thymeleaf-extras-java8time.version>3.0.0.RELEASE</thymeleaf-extras-java8time.version>
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
<assertj.version>3.8.0</assertj.version>

<assertj.version>3.19.0</assertj.version>

<!-- WebJars -->
<webjars.bootstrap.version>3.3.7</webjars.bootstrap.version>
<webjars.jquery.version>3.2.1</webjars.jquery.version>
<webjars.webjars-locator.version>0.40</webjars.webjars-locator.version>
</properties>

<!-- Add typical dependencies for a web application -->
Expand All @@ -57,6 +54,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Thymeleaf with following dialects: Java 8 Time, Layout and Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
Expand All @@ -65,6 +63,14 @@
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand All @@ -73,6 +79,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- WebJars -->
<dependency>
<groupId>org.webjars</groupId>
Expand All @@ -84,12 +91,12 @@
<artifactId>jquery</artifactId>
<version>${webjars.jquery.version}</version>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
</dependency>

<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>${webjars.webjars-locator.version}</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.codeleak.demos.sbt;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.audit.AuditEvent;
import org.springframework.boot.actuate.audit.AuditEventRepository;
import org.springframework.boot.actuate.audit.*;
import org.springframework.boot.actuate.audit.listener.AbstractAuditListener;
import org.springframework.stereotype.Component;

Expand All @@ -15,11 +14,7 @@ public class AuditEventListener extends AbstractAuditListener {

private static final Logger LOG = LoggerFactory.getLogger(AuditEventListener.class);

private final AuditEventRepository auditEventRepository;

public AuditEventListener(AuditEventRepository auditEventRepository) {
this.auditEventRepository = auditEventRepository;
}
private final AuditEventRepository auditEventRepository = new InMemoryAuditEventRepository();

@Override
protected void onAuditEvent(AuditEvent event) {
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#
# Development profile with templates and static resources reloading: http://blog.codeleak.pl/2016/12/thymeleaf-reload-templates-and-static-resources.html
# FIXME: Templates and static reloading does not work currently
#
# Path to project
project.base-dir=file:///C:/Projects/github/spring-boot-thymeleaf

# Path to project (custom property)
project.base-dir=file:///Users/kolorobot/projects/codeleak/spring-boot-thymeleaf

# Templates reloading during development
spring.thymeleaf.prefix=${project.base-dir}/src/main/resources/templates/
spring.thymeleaf.cache=false

# Static resources reloading during development
spring.resources.static-locations=${project.base-dir}/src/main/resources/static/
spring.resources.cache-period=0
spring.web.resources.static-locations=${project.base-dir}/src/main/resources/static/
spring.web.resources.cache.period=0
10 changes: 6 additions & 4 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
spring.thymeleaf.cache=true
security.basic.enabled=false
security.user.name=user
security.user.password=demo
management.security.enabled=${security.basic.enabled}

spring.security.user.name=user
spring.security.user.password=demo

management.endpoints.web.exposure.include=*
management.endpoints.web.base-path=/
16 changes: 1 addition & 15 deletions src/main/resources/static/css/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,4 @@ body {
padding-top: 60px;
padding-bottom: 40px;
background-color: #f5f5f5;
}

.social-links {
max-width: 800px;
margin: 0 auto;
list-style: none;
}

.social-links > li {
width: 30%;
text-align: center;
vertical-align: middle;
display: inline-block;
margin: auto;
}
}
19 changes: 5 additions & 14 deletions src/main/resources/templates/fragments/alert.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link href="/webjars/bootstrap/css/bootstrap.min.css"
th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"
rel="stylesheet" media="screen" />
<link href="/webjars/bootstrap/js/bootstrap.min.js"
th:href="@{/webjars/bootstrap/js/bootstrap.min.js}"
rel="stylesheet" media="screen" />
<script src="/webjars/jquery/jquery.min.js"
th:src="@{/webjars/jquery/jquery.min.js}"></script>
</head>

<body>
<div th:fragment="alert (type, message)" class="alert alert-dismissable" th:classappend="'alert-' + ${type}">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<span th:text="${message}">Test</span>
</div>
<div th:fragment="alert (type, message)" class="alert alert-dismissable" th:classappend="'alert-' + ${type}">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<span th:text="${message}">Test</span>
</div>
</body>
</html>

24 changes: 4 additions & 20 deletions src/main/resources/templates/fragments/footer.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link href="/webjars/bootstrap/css/bootstrap.min.css"
th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"
rel="stylesheet" media="screen" />
</head>
<body>
<div th:fragment="footer">
<ul class="social-links">
<li>
Follow +Kolorobot on <a href="https://plus.google.com/114397026443102745986" rel="publisher" style="text-decoration:none;"><img src="https://ssl.gstatic.com/images/icons/gplus-32.png" style="border:0;width:20px;height:20px;" alt="" /></a>
</li>
<li>
<a href="https://twitter.com/kolorobot" class="twitter-follow-button" data-show-count="false">Follow @kolorobot</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</li>
<li>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://blog.codeleak.pl" data-text="Java, Spring and lots of code" data-via="kolorobot">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</li>
</ul>
</div>
<div th:fragment="footer">
<a href="https://blog.codeleak.pl">Check my blog</a>
<a href="https://twitter.com/kolorobot">Follow me on Twitter (@kolorobot)</a>
</div>
</body>
</html>

12 changes: 0 additions & 12 deletions src/main/resources/templates/fragments/header.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<link href="/webjars/bootstrap/css/bootstrap.min.css"
th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"
rel="stylesheet" media="screen" />
<link href="/webjars/bootstrap/js/bootstrap.min.js"
th:href="@{/webjars/bootstrap/js/bootstrap.min.js}"
rel="stylesheet" media="screen" />
<script src="/webjars/jquery/jquery.min.js"
th:src="@{/webjars/jquery/jquery.min.js}"></script>
</head>
<body>

<!-- Navbar -->
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
Expand Down
Loading

0 comments on commit b44604f

Please sign in to comment.