Update to Thymeleaf 3.0.2 and remove tiles
Spring 5 removed support for Tiles 2 and Thymeleaf does not support Tiles 3 yet. This commit updates to Thymeleaf 3.0.2 and uses Thymeleaf's build in layout support. Issue gh-4080
This commit is contained in:
@@ -16,26 +16,30 @@
|
||||
package org.springframework.security.samples.mvc.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.data.repository.support.DomainClassConverter;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.thymeleaf.extras.tiles2.dialect.TilesDialect;
|
||||
import org.thymeleaf.extras.tiles2.spring4.web.configurer.ThymeleafTilesConfigurer;
|
||||
import org.thymeleaf.extras.tiles2.spring4.web.view.ThymeleafTilesView;
|
||||
import org.thymeleaf.TemplateEngine;
|
||||
import org.thymeleaf.spring4.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
|
||||
@EnableWebMvc
|
||||
@ComponentScan("org.springframework.security.samples.mvc")
|
||||
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private FormattingConversionService mvcConversionService;
|
||||
|
||||
@@ -47,42 +51,34 @@ public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/resources/**")
|
||||
.addResourceLocations("classpath:/resources/").setCachePeriod(31556926);
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/")
|
||||
.setCachePeriod(31556926);
|
||||
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClassLoaderTemplateResolver templateResolver() {
|
||||
ClassLoaderTemplateResolver result = new ClassLoaderTemplateResolver();
|
||||
result.setPrefix("views/");
|
||||
result.setSuffix(".html");
|
||||
result.setTemplateMode("HTML5");
|
||||
return result;
|
||||
public ViewResolver viewResolver() {
|
||||
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
|
||||
resolver.setTemplateEngine(templateEngine());
|
||||
resolver.setCharacterEncoding("UTF-8");
|
||||
return resolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ThymeleafTilesConfigurer tilesConfigurer() {
|
||||
ThymeleafTilesConfigurer tilesConfigurer = new ThymeleafTilesConfigurer();
|
||||
tilesConfigurer.setDefinitions(new String[] { "classpath:tiles/tiles-def.xml" });
|
||||
return tilesConfigurer;
|
||||
public TemplateEngine templateEngine() {
|
||||
SpringTemplateEngine engine = new SpringTemplateEngine();
|
||||
engine.setEnableSpringELCompiler(true);
|
||||
engine.setTemplateResolver(templateResolver());
|
||||
return engine;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SpringTemplateEngine templateEngine(
|
||||
ClassLoaderTemplateResolver templateResolver) {
|
||||
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
|
||||
templateEngine.setTemplateResolver(templateResolver);
|
||||
templateEngine.addDialect(new TilesDialect());
|
||||
return templateEngine;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) {
|
||||
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
|
||||
viewResolver.setTemplateEngine(templateEngine);
|
||||
viewResolver.setViewClass(ThymeleafTilesView.class);
|
||||
return viewResolver;
|
||||
private SpringResourceTemplateResolver templateResolver() {
|
||||
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
|
||||
resolver.setPrefix("classpath:/views/");
|
||||
resolver.setSuffix(".html");
|
||||
resolver.setTemplateMode(TemplateMode.HTML);
|
||||
resolver.setApplicationContext(applicationContext);
|
||||
return resolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||
<!DOCTYPE tiles-definitions PUBLIC
|
||||
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
|
||||
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
|
||||
<tiles-definitions>
|
||||
|
||||
<definition name="messages/*"
|
||||
template="layout">
|
||||
<put-attribute name="content"
|
||||
value="content/messages/{1}"/>
|
||||
<put-attribute name="title"
|
||||
value="title/messages/{1}"/>
|
||||
<put-attribute name="head"
|
||||
value="head/messages/{1}"/>
|
||||
</definition>
|
||||
|
||||
<definition name="content/messages/*"
|
||||
template="messages/{1} :: content"/>
|
||||
<definition name="title/messages/*"
|
||||
template="messages/{1} :: title"/>
|
||||
<definition name="head/messages/*"
|
||||
template="messages/{1} :: /html/head/link"/>
|
||||
|
||||
<definition name="user/*"
|
||||
template="layout">
|
||||
<put-attribute name="content"
|
||||
value="content/user/{1}"/>
|
||||
<put-attribute name="title"
|
||||
value="title/user/{1}"/>
|
||||
<put-attribute name="head"
|
||||
value="head/user/{1}"/>
|
||||
</definition>
|
||||
|
||||
<definition name="content/user/*"
|
||||
template="user/{1} :: content"/>
|
||||
<definition name="title/user/*"
|
||||
template="user/{1} :: title"/>
|
||||
<definition name="head/user/*"
|
||||
template="user/{1} :: /html/head/link"/>
|
||||
|
||||
<definition name="*"
|
||||
template="layout">
|
||||
<put-attribute name="content"
|
||||
value="content/{1}"/>
|
||||
<put-attribute name="title"
|
||||
value="title/{1}"/>
|
||||
<put-attribute name="head"
|
||||
value="head/{1}"/>
|
||||
</definition>
|
||||
|
||||
<definition name="content/*"
|
||||
template="{1} :: content"/>
|
||||
<definition name="title/*"
|
||||
template="{1} :: title"/>
|
||||
<definition name="head/*"
|
||||
template="{1} :: /html/head/link"/>
|
||||
</tiles-definitions>
|
||||
@@ -1,9 +1,8 @@
|
||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-3.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:tiles="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title tiles:include="title">SecureMail:</title>
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:fragment="head(title,links)">
|
||||
<title>SecureMail: <th:block th:include="${title}"></th:block></title>
|
||||
<link rel="icon" type="image/x-icon" th:href="@{/resources/img/favicon.ico}" href="../resources/img/favicon.ico"/>
|
||||
<link th:href="@{/resources/css/bootstrap.css}" href="../resources/css/bootstrap.css" rel="stylesheet"></link>
|
||||
<style type="text/css">
|
||||
@@ -71,11 +70,11 @@
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<script tiles:replace="head"></script>
|
||||
<th:block th:replace="${links}"/>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<body th:fragment="body">
|
||||
<div id="wrap">
|
||||
<div class="navbar navbar-inverse navbar-static-top">
|
||||
<div class="navbar-inner">
|
||||
@@ -105,7 +104,7 @@
|
||||
th:text="${globalMessage}">
|
||||
Some Success message
|
||||
</div>
|
||||
<div tiles:substituteby="content">
|
||||
<div th:replace="${content}">
|
||||
Fake content
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title tiles:fragment="title">Messages : Create</title>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:include="layout :: head(title=~{::title},links=~{})">
|
||||
<title>Create</title>
|
||||
</head>
|
||||
<body>
|
||||
<div tiles:fragment="content">
|
||||
<body th:include="layout :: body" th:with="content=~{::content}">
|
||||
<div th:fragment="content">
|
||||
<div class="container">
|
||||
<h1>Messages : Create</h1>
|
||||
<form id="messageForm"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title tiles:fragment="title">Messages : View All</title>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:include="layout :: head(title=~{::title},links=~{})">
|
||||
<title>View All</title>
|
||||
</head>
|
||||
<body>
|
||||
<div tiles:fragment="content">
|
||||
<body th:include="layout :: body" th:with="content=~{::content}">
|
||||
<div th:fragment="content">
|
||||
<h1>Inbox</h1>
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title tiles:fragment="title">Messages : Create</title>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:include="layout :: head(title=~{::title},links=~{})">
|
||||
<title>Create</title>
|
||||
</head>
|
||||
<body>
|
||||
<div tiles:fragment="content">
|
||||
<body th:include="layout :: body" th:with="content=~{::content}">
|
||||
<div th:fragment="content">
|
||||
<div class="container">
|
||||
<h1>Message : <span th:text="${message.summary}">A short summary...</span></h1>
|
||||
<dl>
|
||||
|
||||
Reference in New Issue
Block a user