Skip to content

Commit b44604f

Browse files
authored
Merge pull request kolorobot#13 from kolorobot/12-spring-boot-2
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.
2 parents fb897a1 + 5eb3b58 commit b44604f

File tree

16 files changed

+221
-327
lines changed

16 files changed

+221
-327
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,49 @@
11
Spring Boot and Thymeleaf with Maven
22
====================================
33

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

1110
Prerequisites
1211
-------------
1312

14-
- JDK 8 and JAVA_HOME environment variable set
13+
- JDK 11 and JAVA_HOME environment variable set
1514

1615
Building the project
1716
--------------------
1817

1918
Clone the repository:
2019

21-
> git clone https://github.com/kolorobot/spring-boot-thymeleaf
20+
git clone https://github.com/kolorobot/spring-boot-thymeleaf
2221

2322
Navigate to the newly created folder:
2423

25-
> cd spring-boot-thymeleaf
24+
cd spring-boot-thymeleaf
2625

2726
Run the project with:
2827

29-
> mvnw clean spring-boot:run
28+
./mvnw clean spring-boot:run
3029

3130
To package the project run:
3231

33-
> mvnw clean package
32+
./mvnw clean package
3433

34+
Open the application
35+
--------------------
36+
37+
Application will be running on http://localhost:8080
38+
39+
To login enter `user` and `demo`
40+
41+
42+
Known issues
43+
------------
44+
45+
- Text templates example does not work
46+
- Selenium configuration does not work
3547

3648
Referenced articles:
3749
--------------------

mvnw

100644100755
File mode changed.

pom.xml

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,44 @@
44

55
<groupId>pl.codeleak.demos.sbt</groupId>
66
<artifactId>spring-boot-thymeleaf</artifactId>
7-
<version>1.0.0-SNAPSHOT</version>
7+
<version>2.0.0</version>
88
<name>spring-boot-thymeleaf</name>
99
<packaging>war</packaging>
1010

11+
<pluginRepositories>
12+
<pluginRepository>
13+
<id>spring-snapshots</id>
14+
<url>https://repo.spring.io/snapshot</url>
15+
</pluginRepository>
16+
<pluginRepository>
17+
<id>spring-milestones</id>
18+
<url>https://repo.spring.io/milestone</url>
19+
</pluginRepository>
20+
</pluginRepositories>
21+
1122
<!-- Inherit defaults from Spring Boot -->
1223
<!-- With this starter it is easier to override versions of libraries -->
24+
1325
<parent>
1426
<groupId>org.springframework.boot</groupId>
1527
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>1.5.4.RELEASE</version>
28+
<version>2.4.5</version>
1729
</parent>
1830

19-
<!-- Spring IO Platform for dependency management -->
20-
<!-- If you are using platform-bom, disable spring-boot-starter-parent -->
21-
<!--<dependencyManagement>-->
22-
<!--<dependencies>-->
23-
<!--<dependency>-->
24-
<!--<groupId>io.spring.platform</groupId>-->
25-
<!--<artifactId>platform-bom</artifactId>-->
26-
<!--<version>2.0.8.RELEASE</version>-->
27-
<!--<type>pom</type>-->
28-
<!--<scope>import</scope>-->
29-
<!--</dependency>-->
30-
<!--</dependencies>-->
31-
<!--</dependencyManagement>-->
32-
3331
<properties>
3432
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35-
<java.version>1.8</java.version>
33+
<java.version>11</java.version>
3634
<maven.compiler.source>${java.version}</maven.compiler.source>
3735
<maven.compiler.target>${java.version}</maven.compiler.target>
3836
<failOnMissingWebXml>false</failOnMissingWebXml>
37+
3938
<!-- Overriding version of selected dependencies -->
40-
<!-- Work when using spring-boot-starter-parent, not platform-bom -->
41-
<thymeleaf.version>3.0.6.RELEASE</thymeleaf.version>
42-
<thymeleaf-extras-java8time.version>3.0.0.RELEASE</thymeleaf-extras-java8time.version>
43-
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
44-
<assertj.version>3.8.0</assertj.version>
45-
39+
<assertj.version>3.19.0</assertj.version>
40+
41+
<!-- WebJars -->
4642
<webjars.bootstrap.version>3.3.7</webjars.bootstrap.version>
4743
<webjars.jquery.version>3.2.1</webjars.jquery.version>
44+
<webjars.webjars-locator.version>0.40</webjars.webjars-locator.version>
4845
</properties>
4946

5047
<!-- Add typical dependencies for a web application -->
@@ -57,6 +54,7 @@
5754
<groupId>org.springframework.boot</groupId>
5855
<artifactId>spring-boot-starter-web</artifactId>
5956
</dependency>
57+
<!-- Thymeleaf with following dialects: Java 8 Time, Layout and Security -->
6058
<dependency>
6159
<groupId>org.springframework.boot</groupId>
6260
<artifactId>spring-boot-starter-thymeleaf</artifactId>
@@ -65,6 +63,14 @@
6563
<groupId>org.thymeleaf.extras</groupId>
6664
<artifactId>thymeleaf-extras-java8time</artifactId>
6765
</dependency>
66+
<dependency>
67+
<groupId>org.thymeleaf.extras</groupId>
68+
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
69+
</dependency>
70+
<dependency>
71+
<groupId>nz.net.ultraq.thymeleaf</groupId>
72+
<artifactId>thymeleaf-layout-dialect</artifactId>
73+
</dependency>
6874
<dependency>
6975
<groupId>org.springframework.boot</groupId>
7076
<artifactId>spring-boot-starter-security</artifactId>
@@ -73,6 +79,7 @@
7379
<groupId>org.springframework.boot</groupId>
7480
<artifactId>spring-boot-starter-actuator</artifactId>
7581
</dependency>
82+
7683
<!-- WebJars -->
7784
<dependency>
7885
<groupId>org.webjars</groupId>
@@ -84,12 +91,12 @@
8491
<artifactId>jquery</artifactId>
8592
<version>${webjars.jquery.version}</version>
8693
</dependency>
87-
8894
<dependency>
89-
<groupId>org.webjars</groupId>
90-
<artifactId>webjars-locator</artifactId>
91-
</dependency>
92-
95+
<groupId>org.webjars</groupId>
96+
<artifactId>webjars-locator</artifactId>
97+
<version>${webjars.webjars-locator.version}</version>
98+
</dependency>
99+
93100
<!-- Test -->
94101
<dependency>
95102
<groupId>org.springframework.boot</groupId>

src/main/java/pl/codeleak/demos/sbt/ServletInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package pl.codeleak.demos.sbt;
22

33
import org.springframework.boot.builder.SpringApplicationBuilder;
4-
import org.springframework.boot.web.support.SpringBootServletInitializer;
4+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
55

66
public class ServletInitializer extends SpringBootServletInitializer {
77

src/main/java/pl/codeleak/demos/sbt/security/AuditEventListener.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
5-
import org.springframework.boot.actuate.audit.AuditEvent;
6-
import org.springframework.boot.actuate.audit.AuditEventRepository;
5+
import org.springframework.boot.actuate.audit.*;
76
import org.springframework.boot.actuate.audit.listener.AbstractAuditListener;
87
import org.springframework.stereotype.Component;
98

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

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

18-
private final AuditEventRepository auditEventRepository;
19-
20-
public AuditEventListener(AuditEventRepository auditEventRepository) {
21-
this.auditEventRepository = auditEventRepository;
22-
}
17+
private final AuditEventRepository auditEventRepository = new InMemoryAuditEventRepository();
2318

2419
@Override
2520
protected void onAuditEvent(AuditEvent event) {
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#
22
# Development profile with templates and static resources reloading: http://blog.codeleak.pl/2016/12/thymeleaf-reload-templates-and-static-resources.html
3+
# FIXME: Templates and static reloading does not work currently
34
#
4-
# Path to project
5-
project.base-dir=file:///C:/Projects/github/spring-boot-thymeleaf
5+
6+
# Path to project (custom property)
7+
project.base-dir=file:///Users/kolorobot/projects/codeleak/spring-boot-thymeleaf
8+
69
# Templates reloading during development
710
spring.thymeleaf.prefix=${project.base-dir}/src/main/resources/templates/
811
spring.thymeleaf.cache=false
12+
913
# Static resources reloading during development
10-
spring.resources.static-locations=${project.base-dir}/src/main/resources/static/
11-
spring.resources.cache-period=0
14+
spring.web.resources.static-locations=${project.base-dir}/src/main/resources/static/
15+
spring.web.resources.cache.period=0
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
spring.thymeleaf.cache=true
2-
security.basic.enabled=false
3-
security.user.name=user
4-
security.user.password=demo
5-
management.security.enabled=${security.basic.enabled}
2+
3+
spring.security.user.name=user
4+
spring.security.user.password=demo
5+
6+
management.endpoints.web.exposure.include=*
7+
management.endpoints.web.base-path=/

src/main/resources/static/css/core.css

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,4 @@ body {
22
padding-top: 60px;
33
padding-bottom: 40px;
44
background-color: #f5f5f5;
5-
}
6-
7-
.social-links {
8-
max-width: 800px;
9-
margin: 0 auto;
10-
list-style: none;
11-
}
12-
13-
.social-links > li {
14-
width: 30%;
15-
text-align: center;
16-
vertical-align: middle;
17-
display: inline-block;
18-
margin: auto;
19-
}
5+
}
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
<!DOCTYPE html>
22
<html xmlns:th="http://www.thymeleaf.org">
3-
<head>
4-
<link href="/webjars/bootstrap/css/bootstrap.min.css"
5-
th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"
6-
rel="stylesheet" media="screen" />
7-
<link href="/webjars/bootstrap/js/bootstrap.min.js"
8-
th:href="@{/webjars/bootstrap/js/bootstrap.min.js}"
9-
rel="stylesheet" media="screen" />
10-
<script src="/webjars/jquery/jquery.min.js"
11-
th:src="@{/webjars/jquery/jquery.min.js}"></script>
12-
</head>
3+
134
<body>
14-
<div th:fragment="alert (type, message)" class="alert alert-dismissable" th:classappend="'alert-' + ${type}">
15-
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
16-
<span th:text="${message}">Test</span>
17-
</div>
5+
<div th:fragment="alert (type, message)" class="alert alert-dismissable" th:classappend="'alert-' + ${type}">
6+
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
7+
<span th:text="${message}">Test</span>
8+
</div>
189
</body>
1910
</html>
2011

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
<!DOCTYPE html>
22
<html xmlns:th="http://www.thymeleaf.org">
3-
<head>
4-
<link href="/webjars/bootstrap/css/bootstrap.min.css"
5-
th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"
6-
rel="stylesheet" media="screen" />
7-
</head>
83
<body>
9-
<div th:fragment="footer">
10-
<ul class="social-links">
11-
<li>
12-
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>
13-
</li>
14-
<li>
15-
<a href="https://twitter.com/kolorobot" class="twitter-follow-button" data-show-count="false">Follow @kolorobot</a>
16-
<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>
17-
</li>
18-
<li>
19-
<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>
20-
<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>
21-
</li>
22-
</ul>
23-
</div>
4+
<div th:fragment="footer">
5+
<a href="https://blog.codeleak.pl">Check my blog</a>
6+
<a href="https://twitter.com/kolorobot">Follow me on Twitter (@kolorobot)</a>
7+
</div>
248
</body>
259
</html>
2610

0 commit comments

Comments
 (0)