Simple Spring/Thymeleaf-App 1.0.0
authorKai Moritz <kai@juplo.de>
Fri, 21 Aug 2015 16:16:33 +0000 (18:16 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 24 Aug 2015 19:12:25 +0000 (21:12 +0200)
This app only serves static content.

We do not need dynamic content to demonstrate the integration, but you
could easily extend this sample to serve dynamically rendered pages.

.gitignore [new file with mode: 0644]
pom.xml [new file with mode: 0644]
src/main/resources/log4j.xml [new file with mode: 0644]
src/main/resources/spring/mvc.xml [new file with mode: 0644]
src/main/webapp/WEB-INF/web.xml [new file with mode: 0644]
src/main/webapp/thymeleaf/a.html [new file with mode: 0644]
src/main/webapp/thymeleaf/b.html [new file with mode: 0644]
src/main/webapp/thymeleaf/c.html [new file with mode: 0644]
src/main/webapp/thymeleaf/index.html [new file with mode: 0644]
src/main/webapp/thymeleaf/templates/layout.html [new file with mode: 0644]
src/test/resources/maven-grunt-integration.properties [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..eb5a316
--- /dev/null
@@ -0,0 +1 @@
+target
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..3cb5566
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,196 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+
+  <groupId>de.juplo</groupId>
+  <artifactId>maven-grunt-integration</artifactId>
+  <name>Juplo - Example Integration of Maven and Grunt</name>
+  <version>0.1</version>
+  <packaging>war</packaging>
+  <url>http://www.juplo.de/maven-grunt-integration</url>
+
+
+  <prerequisites>
+    <maven>3.0.0</maven>
+  </prerequisites>
+
+
+  <scm>
+    <connection>scm:git:http://juplo.de/git/maven-grunt-integration</connection>
+    <developerConnection>scm:git:ssh://juplo.de:/var/lib/git/juplo/maven-grunt-integration</developerConnection>
+    <url>http://juplo.de/gitweb/?p=maven-grunt-integration;a=summary</url>
+  </scm>
+
+
+  <developers>
+    <developer>
+      <id>kai</id>
+      <name>Kai Moritz</name>
+      <email>kai@juplo.de</email>
+    </developer>
+  </developers>
+
+
+  <properties>
+
+    <!-- Zeichensatz -->
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+    <!-- Verwendete Versionen -->
+    <servlet-api.version>3.1.0</servlet-api.version>
+    <slf4j.version>1.7.12</slf4j.version>
+    <springframework.version>4.2.0.RELEASE</springframework.version>
+    <thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
+    <thymeleaf-layout-dialect.version>1.2.9</thymeleaf-layout-dialect.version>
+
+  </properties>
+
+
+  <dependencies>
+
+    <!-- Spring -->
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-webmvc</artifactId>
+      <version>${springframework.version}</version>
+    </dependency>
+
+    <!-- Thymeleaf -->
+    <dependency>
+      <groupId>org.thymeleaf</groupId>
+      <artifactId>thymeleaf</artifactId>
+      <version>${thymeleaf.version}</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.thymeleaf</groupId>
+      <artifactId>thymeleaf-spring4</artifactId>
+      <version>${thymeleaf.version}</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>nz.net.ultraq.thymeleaf</groupId>
+      <artifactId>thymeleaf-layout-dialect</artifactId>
+      <version>${thymeleaf-layout-dialect.version}</version>
+      <scope>runtime</scope>
+    </dependency>
+
+    <!-- Servlet -->
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <version>${servlet-api.version}</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>${slf4j.version}</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <version>${slf4j.version}</version>
+      <scope>runtime</scope>
+    </dependency>
+
+  </dependencies>
+
+
+  <distributionManagement>
+    <repository>
+      <id>juplo.internal</id>
+      <name>Internal Release Repository</name>
+      <url>http://juplo.de/archiva/repository/internal/</url>
+    </repository>
+    <snapshotRepository>
+      <id>juplo.snapshots</id>
+      <name>Internal Snapshot Repository</name>
+      <url>http://juplo.de/archiva/repository/snapshots/</url>
+    </snapshotRepository>
+  </distributionManagement>
+
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.3</version>
+        <configuration>
+          <source>1.7</source>
+          <target>1.7</target>
+          <encoding>utf8</encoding>
+          <showWarnings>true</showWarnings>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>2.4</version>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.eclipse.jetty</groupId>
+        <artifactId>jetty-maven-plugin</artifactId>
+        <version>9.2.13.v20150730</version>
+        <configuration>
+          <useTestScope>true</useTestScope>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <version>2.11</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>2.10.3</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jxr-plugin</artifactId>
+        <version>2.5</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-report-plugin</artifactId>
+        <version>2.18.1</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-scm-plugin</artifactId>
+        <version>1.9.4</version>
+        <configuration>
+          <goals>install</goals>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+
+</project>
diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml
new file mode 100644 (file)
index 0000000..a3d7d44
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%p - %C{1}.%M(%L) | %m%n"/>
+    </layout>
+  </appender>
+
+  <logger name="de.juplo">
+   <level value="trace"/>
+  </logger>
+
+  <logger name="org.springframework">
+    <level value="debug" />
+  </logger>
+  <logger name="org.thymeleaf">
+    <level value="debug" />
+  </logger>
+
+  <root>
+    <level value="info"/>
+    <appender-ref ref="CONSOLE"/>
+  </root>
+
+</log4j:configuration>
diff --git a/src/main/resources/spring/mvc.xml b/src/main/resources/spring/mvc.xml
new file mode 100644 (file)
index 0000000..3504d43
--- /dev/null
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:mvc="http://www.springframework.org/schema/mvc"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+           http://www.springframework.org/schema/beans
+           http://www.springframework.org/schema/beans/spring-beans.xsd
+           http://www.springframework.org/schema/mvc
+           http://www.springframework.org/schema/mvc/spring-mvc.xsd
+           http://www.springframework.org/schema/context
+           http://www.springframework.org/schema/context/spring-context.xsd
+           http://www.springframework.org/schema/util
+           http://www.springframework.org/schema/util/spring-util.xsd
+           ">
+
+  <!-- Resolve app-parameters through java-systemproperties -->
+  <context:property-placeholder location="classpath:maven-grunt-integration.properties" />
+
+  <!-- Needed, to map the servlet on /* -->
+  <mvc:default-servlet-handler/>
+  <mvc:view-controller path="/" view-name="index"/>
+
+  <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
+    <property name="mappings">
+      <value>
+        /thymeleaf/**=staticResources
+        /*.html=urlFilenameViewController
+        /**/*.html=urlFilenameViewController
+      </value>
+    </property>
+    <property name="order" value="10"/>
+  </bean>
+  <bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
+  <bean id="staticResources" class="org.springframework.web.servlet.resource.ResourceHttpRequestHandler">
+    <property name="locations">
+      <list>
+        <value>/thymeleaf/</value>
+      </list>
+    </property>
+  </bean>
+
+  <!-- Thymeleaf Spring-View-Resolver -->
+  <bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
+    <property name="templateEngine" ref="templateEngine" />
+    <property name="characterEncoding" value="UTF-8" />
+    <property name="contentType" value="text/html; charset=UTF-8" />
+  </bean>
+
+
+  <!-- Thymeleaf Template-Resolver -->
+  <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
+    <property name="prefix" value="/thymeleaf/" />
+    <property name="suffix" value=".html" />
+    <property name="templateMode" value="HTML5" />
+    <property name="characterEncoding" value="UTF-8" />
+    <property name="cacheable" value="${maven-grunt-integration.cacheable}" />
+  </bean>
+
+  <!-- Thymeleaf Spring4-Template-Engine -->
+  <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
+    <property name="templateResolver" ref="templateResolver" />
+    <property name="additionalDialects">
+      <util:set>
+        <bean class="nz.net.ultraq.thymeleaf.LayoutDialect"/>
+      </util:set>
+    </property>
+  </bean>
+
+</beans>
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
new file mode 100644 (file)
index 0000000..92eae0e
--- /dev/null
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
+  version="3.1">
+
+  <display-name>maven-grunt-integration</display-name>
+
+  <!-- Context Configuration locations for Spring XML files -->
+
+  <context-param>
+    <param-name>contextConfigLocation</param-name>
+    <param-value>
+      classpath:/spring/mvc.xml
+    </param-value>
+  </context-param>
+
+  <listener>
+    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+  </listener>
+
+
+  <!-- UTF-8 -->
+
+  <filter>
+    <filter-name>characterEncodingFilter</filter-name>
+    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
+    <init-param>
+      <param-name>encoding</param-name>
+      <param-value>UTF-8</param-value>
+    </init-param>
+    <init-param>
+      <param-name>forceEncoding</param-name>
+      <param-value>true</param-value>
+    </init-param>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>characterEncodingFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
+
+
+  <!-- Handles all requests into the application -->
+
+  <servlet>
+    <servlet-name>Dispatcher Servlet - Maven/Grunt-Integration</servlet-name>
+    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+    <init-param>
+      <param-name>contextConfigLocation</param-name>
+      <param-value>
+      </param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>Dispatcher Servlet - Maven/Grunt-Integration</servlet-name>
+    <url-pattern>/</url-pattern>
+  </servlet-mapping>
+
+</web-app>
diff --git a/src/main/webapp/thymeleaf/a.html b/src/main/webapp/thymeleaf/a.html
new file mode 100644 (file)
index 0000000..24aa688
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html layout:decorator="templates/layout" th:with="title='A'">
+
+<head>
+
+  <!--/*-->
+  <meta charset="utf-8" />
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta name="viewport" content="width=device-width, initial-scale=1" />
+  <!--*/-->
+
+  <title>Maven/Grunt-Integration - A</title>
+
+</head>
+
+<body>
+
+
+  <article layout:fragment="content">
+    <h1>A</h1>
+    <p>Content of page A.</p>
+  </article>
+
+  <h1>Menu for page A</h1>
+  <ul layout:fragment="menu">
+    <li><a href="#" th:href="@{/}">Home</a></li>
+    <li><strong>A</strong></li>
+    <li><a href="#" th:href="@{/b.html}">B</a></li>
+    <li><a href="#" th:href="@{/c.html}">C</a></li>
+  </ul>
+
+
+</body>
+
+</html>
diff --git a/src/main/webapp/thymeleaf/b.html b/src/main/webapp/thymeleaf/b.html
new file mode 100644 (file)
index 0000000..48bbff5
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html layout:decorator="templates/layout" th:with="title='B'">
+
+<head>
+
+  <!--/*-->
+  <meta charset="utf-8" />
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta name="viewport" content="width=device-width, initial-scale=1" />
+  <!--*/-->
+
+  <title>Maven/Grunt-Integration - B</title>
+
+</head>
+
+<body>
+
+
+  <article layout:fragment="content">
+    <h1>B</h1>
+    <p>Content of page B.</p>
+  </article>
+
+  <h1>Menu for page B</h1>
+  <ul layout:fragment="menu">
+    <li><a href="#" th:href="@{/}">Home</a></li>
+    <li><a href="#" th:href="@{/a.html}">A</a></li>
+    <li><strong>B</strong></li>
+    <li><a href="#" th:href="@{/c.html}">C</a></li>
+  </ul>
+
+
+</body>
+
+</html>
diff --git a/src/main/webapp/thymeleaf/c.html b/src/main/webapp/thymeleaf/c.html
new file mode 100644 (file)
index 0000000..d41c83e
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html layout:decorator="templates/layout" th:with="title='C'">
+
+<head>
+
+  <!--/*-->
+  <meta charset="utf-8" />
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta name="viewport" content="width=device-width, initial-scale=1" />
+  <!--*/-->
+
+  <title>Maven/Grunt-Integration - C</title>
+
+</head>
+
+<body>
+
+
+  <article layout:fragment="content">
+    <h1>C</h1>
+    <p>Content of page C.</p>
+  </article>
+
+  <h1>Menu for page C</h1>
+  <ul layout:fragment="menu">
+    <li><a href="#" th:href="@{/}">Home</a></li>
+    <li><a href="#" th:href="@{/a.html}">A</a></li>
+    <li><a href="#" th:href="@{/b.html}">B</a></li>
+    <li><strong>C</strong></li>
+  </ul>
+
+
+</body>
+
+</html>
diff --git a/src/main/webapp/thymeleaf/index.html b/src/main/webapp/thymeleaf/index.html
new file mode 100644 (file)
index 0000000..8f2e336
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html layout:decorator="templates/layout" th:with="title='Home'">
+
+<head>
+
+  <!--/*-->
+  <meta charset="utf-8" />
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta name="viewport" content="width=device-width, initial-scale=1" />
+  <!--*/-->
+
+  <title>Maven/Grunt-Integration</title>
+
+</head>
+
+<body>
+
+
+  <article layout:fragment="content">
+    <h1>Home</h1>
+    <p>Content of page home.</p>
+  </article>
+
+  <h1>Menu for page Home</h1>
+  <ul layout:fragment="menu">
+    <li><strong>Home</strong></li>
+    <li><a href="#" th:href="@{/a.html}">A</a></li>
+    <li><a href="#" th:href="@{/b.html}">B</a></li>
+    <li><a href="#" th:href="@{/c.html}">C</a></li>
+  </ul>
+
+
+</body>
+
+</html>
diff --git a/src/main/webapp/thymeleaf/templates/layout.html b/src/main/webapp/thymeleaf/templates/layout.html
new file mode 100644 (file)
index 0000000..7f69a65
--- /dev/null
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.thymeleaf.org">
+
+<head>
+
+  <meta charset="utf-8" />
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta name="viewport" content="width=device-width, initial-scale=1" />
+
+  <title layout:title-pattern="Maven/Grunt-Integration - $CONTENT_TITLE">Layout-Template</title>
+
+</head>
+
+<body>
+
+  <header>
+    <h2 th:text="'Maven/Grunt-Integration :: ' + ${title}">Maven/Grunt-Integration :: Layout-Template</h2>
+    <hr />
+    <!-- Navigation -->
+    <nav id="menu" class="navbar navbar-submenu navbar-fixed-top">
+      <h3 class="sr-only">Navigation</h3>
+      <ul layout:fragment="menu">
+        <li><strong>Home</strong></li>
+        <li><a href="#">A</a></li>
+        <li><a href="#">B</a></li>
+        <li><a href="#">C</a></li>
+      </ul>
+    </nav>
+    <hr />
+  </header>
+
+
+  <main>
+
+    <article layout:fragment="content">
+      <h1>Layout-Template</h1>
+      <p>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+        eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
+        ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+        aliquip ex ea commodo consequat. Duis aute irure dolor in
+        reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+        pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+        culpa qui officia deserunt mollit anim id est laborum.
+      </p>
+      <h2>Duis aute irure dolor</h2>
+      <ul>
+        <li>Operators and other mathematical stuff: -+/*</li>
+        <li>
+          Characters offten used in programming languages:
+          {(&lt;&gt;)}@$?%*#;:&amp;/\!^&#034;&#039;`~
+        </li>
+        <li>Special german characters: ÄäÖöÜü</li>
+        <li>Other special characters: @?¢§%°</li>
+      </ul>
+      <h2>Excepteur sint occaecat cupidatat</h2>
+      <p>
+        Lorem ipsum dolor <em>sit amet</em>, consectetur adipisicing elit,
+        sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+        nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+        reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+        pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+        culpa qui officia deserunt mollit anim id est laborum.
+      </p>
+      <p>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+        eiusmod tempor incididunt ut labore et dolore magna aliqua.
+        <strong>Ut enim ad minim veniam, quis nostrud <em>exercitation
+        ullamco</em> laboris nisi ut aliquip ex ea commodo consequat</strong>.
+        Duis aute irure dolor in reprehenderit in voluptate velit esse
+        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
+        cupidatat non proident, sunt in culpa qui officia deserunt mollit
+        anim id est laborum.
+      </p>
+    </article>
+
+  </main>
+
+  <footer>
+    <hr />
+    Brought to you by <a href="http://juplo.de/">juplo.de</a>!
+  </footer>
+
+</body>
+
+</html>
diff --git a/src/test/resources/maven-grunt-integration.properties b/src/test/resources/maven-grunt-integration.properties
new file mode 100644 (file)
index 0000000..8b23fdf
--- /dev/null
@@ -0,0 +1 @@
+maven-grunt-integration.cacheable=false