├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── client ├── .bowerrc ├── .gitignore ├── build.gradle ├── gulpfile.js ├── package.json ├── pom.xml └── src │ ├── app │ ├── app.js │ ├── model.js │ └── ui.js │ ├── cache.manifest │ ├── config.js │ ├── css │ └── main.css │ ├── img │ └── spring-logo.png │ └── less │ └── style.less ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pom.xml ├── server ├── build.gradle ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── springframework │ │ └── samples │ │ └── resources │ │ ├── Application.java │ │ ├── WebConfig.java │ │ └── handlebars │ │ ├── ProfileHelper.java │ │ └── ResourceUrlHelper.java │ ├── resources │ ├── application.yml │ ├── groovy │ │ └── hello.tpl │ ├── handlebars │ │ ├── app.hbs │ │ ├── index.hbs │ │ └── less.hbs │ └── logback.xml │ └── webapp │ └── WEB-INF │ └── jsp │ └── hellojsp.jsp └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.sw[op] 2 | .DS_Store 3 | 4 | # IDEA 5 | .idea 6 | *.iml 7 | *.ipr 8 | *.iws 9 | out 10 | 11 | # Gradle 12 | .gradle 13 | build 14 | 15 | # Maven 16 | target 17 | dist 18 | node 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2015-Present Pivotal Software Inc. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Spring Resource Handling 2 | ======================== 3 | 4 | This application demonstrates new resource handling features in Spring Framework 4.1. 5 | It was originally developed for the talk [Resource Handling in Spring MVC 4.1](https://2014.event.springone2gx.com/schedule/sessions/resource_handling_in_spring_mvc_4_1.html) talk at SpringOne2GX 2014. 6 | 7 | 8 | This projects requires a local install of node+npm (see [nvm](https://github.com/creationix/nvm)). 9 | 10 | The easiest way to get started - from the project root - development version: 11 | 12 | SPRING_PROFILES_ACTIVE=development RESOURCES_PROJECTROOT=`pwd` ./gradlew :server:bootRun 13 | 14 | Or the production version (more optimizations): 15 | 16 | ./gradlew :server:bootRun 17 | 18 | Then go to: 19 | 20 | * http://localhost:8080/ for an example with Handlebars templating 21 | * http://localhost:8080/groovy for an example with Groovy Template Engine 22 | * http://localhost:8080/app for an example with an [HTML5 AppCache Manifest](http://www.html5rocks.com/en/tutorials/appcache/beginner/) 23 | (you can check this in Chrome with chrome://appcache-internals/ ) 24 | * http://localhost:8080/less for an example with a LESS stylesheet; this page uses less files and the LESS JS transpiler 25 | in development mode, and a transpiled version in production 26 | * http://localhost:8080/jsp for a JSP example 27 | 28 | Interesting parts of the application: 29 | 30 | * [configuring resource handlers with resource resolvers and resource transformers](https://github.com/bclozel/spring-resource-handling/blob/master/server/src/main/java/org/springframework/samples/resources/WebConfig.java#L96-L117) 31 | * [a sample template file using handlebars.java](https://github.com/bclozel/spring-resource-handling/blob/master/server/src/main/resources/handlebars/index.hbs) 32 | and a [custom handlebars helper](https://github.com/bclozel/spring-resource-handling/blob/master/server/src/main/java/org/springframework/samples/resources/handlebars/ResourceUrlHelper.java) to resolve URLs to static resources 33 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | task wrapper(type: Wrapper) { 2 | gradleVersion = '2.3' 3 | } 4 | -------------------------------------------------------------------------------- /client/.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "src/lib" 3 | } -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | src/lib 2 | node_modules 3 | npm-debug.log 4 | .cram/ 5 | dist/ -------------------------------------------------------------------------------- /client/build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.taskdefs.condition.Os 2 | 3 | apply plugin: 'java' 4 | 5 | jar { 6 | from 'dist' 7 | eachFile { details -> 8 | details.path = details.path.startsWith('META-INF') ?: 'static/'+details.path 9 | } 10 | // Jar has duplicate empty folders (see http://issues.gradle.org/browse/GRADLE-1830) 11 | // So we need to set includeEmptyDirs to false 12 | includeEmptyDirs = false 13 | } 14 | 15 | task npmInstall(type:Exec) { 16 | 17 | logging.captureStandardOutput LogLevel.INFO // be Gradle-like, reduce noisy logging 18 | logging.captureStandardError LogLevel.LIFECYCLE // but do show downloads in the log 19 | 20 | inputs.files "package.json", "bower.json" 21 | outputs.files "node_modules", "src/lib" 22 | 23 | if(Os.isFamily(Os.FAMILY_WINDOWS)) { 24 | commandLine 'cmd', '/c', 'npm', 'install' 25 | } 26 | else { 27 | commandLine 'npm', 'install' 28 | } 29 | } 30 | 31 | task npmBuild(type:Exec, dependsOn: npmInstall) { 32 | 33 | logging.captureStandardOutput LogLevel.INFO 34 | logging.captureStandardError LogLevel.INFO 35 | 36 | inputs.dir "src" 37 | inputs.file "gulpfile.js" 38 | outputs.dir "dist" 39 | 40 | if(Os.isFamily(Os.FAMILY_WINDOWS)) { 41 | commandLine 'cmd', '/c', 'npm', 'run', 'build' 42 | } 43 | else { 44 | commandLine 'npm', 'run', 'build' 45 | } 46 | } 47 | 48 | jar.dependsOn npmBuild -------------------------------------------------------------------------------- /client/gulpfile.js: -------------------------------------------------------------------------------- 1 | 2 | var path = require('path'), 3 | cssMinify = require('gulp-minify-css'), 4 | less = require('gulp-less'), 5 | gulp = require('gulp'), 6 | Builder = require('systemjs-builder'); 7 | 8 | var paths = { 9 | baseUrl: 'file:' + process.cwd() + '/src/', 10 | bowerLibs: ['src/lib/**', '!src/lib/*/test/*'], 11 | css: { 12 | files: ['src/css/*.css'], 13 | root: 'src/css' 14 | }, 15 | less: ['src/less/*'], 16 | assets: ["src/cache.manifest"], 17 | images: ["src/img/*"], 18 | destination: './dist' 19 | }; 20 | 21 | // Optimize application CSS files and copy to "dist" folder 22 | gulp.task('optimize-and-copy-css', function() { 23 | return gulp.src(paths.css.files) 24 | .pipe(cssMinify({root : paths.css.root, noRebase: true})) 25 | .pipe(gulp.dest(paths.destination + '/css')); 26 | }); 27 | 28 | // Optimize application JavaScript files and copy to "dist" folder 29 | gulp.task('optimize-and-copy-js', function(cb) { 30 | var builder = new Builder(); 31 | builder.loadConfig('./src/config.js') 32 | .then(function() { 33 | builder.config({ baseURL: paths.baseUrl }); 34 | builder.build('app/app', paths.destination + '/app/app.js', { minify: true, sourceMaps: true }); 35 | cb(); 36 | }) 37 | .catch(function(err) { 38 | cb(err); 39 | }); 40 | }); 41 | 42 | // Copy jspm-managed JavaScript dependencies to "dist" folder 43 | gulp.task('copy-lib', function() { 44 | return gulp.src(paths.bowerLibs) 45 | .pipe(gulp.dest(paths.destination + '/lib')); 46 | }); 47 | 48 | gulp.task('copy-images', function() { 49 | return gulp.src(paths.images) 50 | .pipe(gulp.dest(paths.destination + '/img')); 51 | }); 52 | 53 | gulp.task('copy-assets', function() { 54 | return gulp.src(paths.assets) 55 | .pipe(gulp.dest(paths.destination)) 56 | }); 57 | 58 | gulp.task('less', function () { 59 | return gulp.src(paths.less) 60 | .pipe(less()) 61 | .pipe(cssMinify({noRebase: true})) 62 | .pipe(gulp.dest(paths.destination + '/css')); 63 | }); 64 | 65 | gulp.task('build', ['optimize-and-copy-css', 'optimize-and-copy-js', 'copy-lib', 66 | 'copy-images', 'less', 'copy-assets'], function(){}); -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spring-resource-handling", 3 | "version": "0.0.1", 4 | "description": "Spring Resources Handling sample", 5 | "dependencies": { 6 | "jspm": "^0.15.2", 7 | "gulp": "^3.8.11", 8 | "gulp-less": "^3.0.3", 9 | "gulp-minify-css": "^1.1.0", 10 | "gulp-util": "^3.0.4", 11 | "systemjs-builder": "^0.10.4" 12 | }, 13 | "scripts": { 14 | "prepublish": "jspm install", 15 | "build": "gulp build" 16 | }, 17 | "engines": { 18 | "node": ">=0.10.0" 19 | }, 20 | "jspm": { 21 | "directories": { 22 | "baseURL": "src", 23 | "packages": "src/lib" 24 | }, 25 | "dependencies": { 26 | "bootstrap": "github:twbs/bootstrap@^3.3.4", 27 | "jquery": "github:components/jquery@^2.1.3", 28 | "less": "github:aaike/jspm-less-plugin@^0.0.5" 29 | }, 30 | "devDependencies": { 31 | "traceur": "github:jmcriffey/bower-traceur@0.0.87", 32 | "traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.87" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.samples 7 | spring-resource-handling-client 8 | 0.1.0.BUILD-SNAPSHOT 9 | jar 10 | 11 | Spring Resource Handling Client module 12 | 13 | 14 | org.springframework.samples 15 | spring-resource-handling 16 | 0.1.0.BUILD-SNAPSHOT 17 | ../ 18 | 19 | 20 | 21 | 22 | 23 | com.github.eirslett 24 | frontend-maven-plugin 25 | 0.0.23 26 | 27 | 28 | install node and npm 29 | install-node-and-npm 30 | 31 | v0.10.38 32 | 1.4.28 33 | 34 | 35 | 36 | npm install 37 | npm 38 | 39 | 40 | npm build 41 | npm 42 | 43 | run build 44 | 45 | 46 | 47 | 48 | 49 | maven-resources-plugin 50 | 2.7 51 | 52 | 53 | copy-resources 54 | package 55 | 56 | copy-resources 57 | 58 | 59 | ${project.build.directory}/classes/static 60 | 61 | 62 | ${basedir}/dist 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /client/src/app/app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var ui = require('./ui'); 4 | var $ = require('jquery'); 5 | 6 | ui.update(); -------------------------------------------------------------------------------- /client/src/app/model.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | define([], function() { 4 | 5 | return { 6 | getMessage: function() { 7 | return "Hello world!"; 8 | } 9 | } 10 | }); -------------------------------------------------------------------------------- /client/src/app/ui.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | define(["jquery", "app/model"], function($, ui) { 4 | 5 | return { 6 | update: function() { 7 | $("#greeting").html(ui.getMessage()); 8 | } 9 | } 10 | }); -------------------------------------------------------------------------------- /client/src/cache.manifest: -------------------------------------------------------------------------------- 1 | CACHE MANIFEST 2 | 3 | # this is a comment 4 | CACHE: 5 | lib/curl/src/curl.js 6 | run.js 7 | 8 | NETWORK: 9 | * 10 | 11 | CACHE: 12 | css/main.css 13 | img/spring-logo.png 14 | https://fonts.googleapis.com/css?family=Varela+Round|Montserrat:400,700 -------------------------------------------------------------------------------- /client/src/config.js: -------------------------------------------------------------------------------- 1 | System.config({ 2 | "baseURL": "/", 3 | "paths": { 4 | "*": "*.js", 5 | "github:*": "lib/github/*.js" 6 | } 7 | }); 8 | 9 | System.config({ 10 | "map": { 11 | "bootstrap": "github:twbs/bootstrap@3.3.4", 12 | "jquery": "github:components/jquery@2.1.3", 13 | "less": "github:aaike/jspm-less-plugin@0.0.5", 14 | "traceur": "github:jmcriffey/bower-traceur@0.0.87", 15 | "traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.87", 16 | "github:aaike/jspm-less-plugin@0.0.5": { 17 | "less.js": "github:distros/less@2.4.0" 18 | }, 19 | "github:twbs/bootstrap@3.3.4": { 20 | "jquery": "github:components/jquery@2.1.3" 21 | } 22 | } 23 | }); 24 | 25 | -------------------------------------------------------------------------------- /client/src/css/main.css: -------------------------------------------------------------------------------- 1 | @import url("../lib/github/twbs/bootstrap@3.3.4/css/bootstrap.css"); 2 | 3 | #logo { 4 | width: 100%; 5 | height: 200px; 6 | background: url('/img/spring-logo.png') no-repeat 50% 50%; 7 | background-size: 450px; 8 | color:white; 9 | } -------------------------------------------------------------------------------- /client/src/img/spring-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringOne2GX-2014/spring-resource-handling/8f1c7fca81ddeb155ecffb91a691279597aaf822/client/src/img/spring-logo.png -------------------------------------------------------------------------------- /client/src/less/style.less: -------------------------------------------------------------------------------- 1 | @import "../lib/github/twbs/bootstrap@3.3.4/css/bootstrap.css"; 2 | 3 | @images: "../img"; 4 | 5 | #logo { 6 | width: 100%; 7 | height: 200px; 8 | background: url("@{images}/spring-logo.png") no-repeat 50% 50%; 9 | background-size: 450px; 10 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=0.1-SNAPSHOT 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringOne2GX-2014/spring-resource-handling/8f1c7fca81ddeb155ecffb91a691279597aaf822/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Mar 03 14:10:21 CET 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.samples 7 | spring-resource-handling 8 | 0.1.0.BUILD-SNAPSHOT 9 | pom 10 | 11 | Spring Resource Handling 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.2.3.RELEASE 17 | 18 | 19 | 20 | client 21 | server 22 | 23 | 24 | 25 | UTF-8 26 | 1.8 27 | 28 | 29 | 30 | 31 | spring-snapshots 32 | spring-snapshots 33 | 34 | http://repo.spring.io/libs-snapshot 35 | 36 | 37 | 38 | 39 | spring-snapshots 40 | spring-snapshots 41 | 42 | http://repo.spring.io/libs-snapshot 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /server/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.2.3.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | maven{ 8 | url 'http://repo.spring.io/libs-snapshot' 9 | } 10 | } 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | classpath("io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE") 14 | } 15 | } 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'spring-boot' 19 | apply plugin: 'io.spring.dependency-management' 20 | 21 | repositories { 22 | mavenCentral() 23 | maven{ 24 | url 'http://repo.spring.io/libs-snapshot' 25 | 26 | } 27 | } 28 | 29 | ext { 30 | javaVersion = '1.8'; 31 | } 32 | 33 | sourceCompatibility = javaVersion 34 | targetCompatibility = javaVersion 35 | 36 | jar { 37 | baseName = 'spring-resource-handling' 38 | version = '0.1.0.BUILD-SNAPSHOT' 39 | } 40 | 41 | // war build 42 | /* 43 | apply plugin: 'war' 44 | war { 45 | baseName = 'spring-resource-handling' 46 | version = '0.1.0.BUILD-SNAPSHOT' 47 | } 48 | */ 49 | 50 | configurations { 51 | providedRuntime 52 | } 53 | 54 | dependencies { 55 | compile project(':client') 56 | compile("org.springframework.boot:spring-boot-starter-web") 57 | 58 | compile("org.apache.tomcat.embed:tomcat-embed-jasper") 59 | compile("javax.servlet:jstl") 60 | compile("com.github.jknack:handlebars-springmvc:2.0.0") 61 | compile("org.codehaus.groovy:groovy-all") 62 | 63 | testCompile("org.springframework.boot:spring-boot-starter-test") 64 | testCompile("org.testng:testng") 65 | } -------------------------------------------------------------------------------- /server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.samples 7 | spring-resource-handling-server 8 | 0.1.0.BUILD-SNAPSHOT 9 | war 10 | 11 | Spring Resource Handling Server Module 12 | 13 | 14 | org.springframework.samples 15 | spring-resource-handling 16 | 0.1.0.BUILD-SNAPSHOT 17 | ../ 18 | 19 | 20 | 21 | org.springframework.samples.resources.Application 22 | 23 | 24 | 25 | 26 | org.springframework.samples 27 | spring-resource-handling-client 28 | 0.1.0.BUILD-SNAPSHOT 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-web 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-tomcat 37 | provided 38 | 39 | 40 | com.github.jknack 41 | handlebars-springmvc 42 | 2.0.0 43 | 44 | 45 | org.codehaus.groovy 46 | groovy-all 47 | 48 | 49 | javax.servlet 50 | javax.servlet-api 51 | 3.0.1 52 | provided 53 | 54 | 55 | javax.servlet 56 | jstl 57 | 58 | 59 | org.apache.tomcat.embed 60 | tomcat-embed-jasper 61 | provided 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /server/src/main/java/org/springframework/samples/resources/Application.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.resources; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.context.web.SpringBootServletInitializer; 7 | 8 | @SpringBootApplication 9 | public class Application extends SpringBootServletInitializer { 10 | 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | 16 | @Override 17 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 18 | return application.sources(Application.class); 19 | } 20 | } -------------------------------------------------------------------------------- /server/src/main/java/org/springframework/samples/resources/WebConfig.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.resources; 2 | 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.function.Function; 7 | 8 | import javax.annotation.PostConstruct; 9 | 10 | import com.github.jknack.handlebars.springmvc.HandlebarsViewResolver; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.context.annotation.Bean; 15 | import org.springframework.context.annotation.Configuration; 16 | import org.springframework.core.env.Environment; 17 | import org.springframework.samples.resources.handlebars.ProfileHelper; 18 | import org.springframework.samples.resources.handlebars.ResourceUrlHelper; 19 | import org.springframework.util.Assert; 20 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 21 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 22 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 23 | import org.springframework.web.servlet.resource.AppCacheManifestTransformer; 24 | import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter; 25 | import org.springframework.web.servlet.resource.ResourceUrlProvider; 26 | import org.springframework.web.servlet.resource.VersionResourceResolver; 27 | import org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver; 28 | 29 | @Configuration 30 | public class WebConfig extends WebMvcConfigurerAdapter { 31 | 32 | @Autowired 33 | private Environment env; 34 | 35 | @Autowired 36 | private GroovyMarkupViewResolver groovyMarkupViewResolver; 37 | 38 | @Autowired 39 | private ResourceUrlProvider urlProvider; 40 | 41 | @Value("${resources.projectroot:}") 42 | private String projectRoot; 43 | 44 | @Value("${app.version:}") 45 | private String appVersion; 46 | 47 | 48 | private String getProjectRootRequired() { 49 | Assert.state(this.projectRoot != null, "Please set \"resources.projectRoot\" in application.yml"); 50 | return this.projectRoot; 51 | } 52 | 53 | @Override 54 | public void addViewControllers(ViewControllerRegistry registry) { 55 | registry.addViewController("/").setViewName("index"); 56 | registry.addViewController("/groovy").setViewName("hello"); 57 | registry.addViewController("/app").setViewName("app"); 58 | registry.addViewController("/less").setViewName("less"); 59 | registry.addViewController("/jsp").setViewName("hellojsp"); 60 | } 61 | 62 | @Bean 63 | public HandlebarsViewResolver handlebarsViewResolver() { 64 | HandlebarsViewResolver resolver = new HandlebarsViewResolver(); 65 | resolver.setPrefix("classpath:/handlebars/"); 66 | resolver.registerHelper("src", new ResourceUrlHelper(this.urlProvider)); 67 | resolver.registerHelper(ProfileHelper.NAME, new ProfileHelper(this.env.getActiveProfiles())); 68 | resolver.setCache(!this.env.acceptsProfiles("development")); 69 | resolver.setFailOnMissingFile(false); 70 | resolver.setAttributesMap(Collections.singletonMap("applicationVersion", getApplicationVersion())); 71 | return resolver; 72 | } 73 | 74 | @PostConstruct 75 | public void registerGroovyTemplateHelpers() { 76 | Map groovyTemplateHelpers = new HashMap<>(); 77 | groovyTemplateHelpers.put("linkTo", s -> this.urlProvider.getForLookupPath((String) s)); 78 | groovyTemplateHelpers.put("appVersion", s -> getApplicationVersion()); 79 | this.groovyMarkupViewResolver.setAttributesMap(groovyTemplateHelpers); 80 | } 81 | 82 | @Bean 83 | public ResourceUrlEncodingFilter resourceUrlEncodingFilter() { 84 | return new ResourceUrlEncodingFilter(); 85 | } 86 | 87 | @Override 88 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 89 | 90 | boolean devMode = this.env.acceptsProfiles("development"); 91 | 92 | String location = devMode ? "file:///" + getProjectRootRequired() + "/client/src/" : "classpath:static/"; 93 | Integer cachePeriod = devMode ? 0 : null; 94 | boolean useResourceCache = !devMode; 95 | String version = getApplicationVersion(); 96 | 97 | AppCacheManifestTransformer appCacheTransformer = new AppCacheManifestTransformer(); 98 | VersionResourceResolver versionResolver = new VersionResourceResolver() 99 | .addFixedVersionStrategy(version, "/**/*.js", "/**/*.map") 100 | .addContentVersionStrategy("/**"); 101 | 102 | registry.addResourceHandler("/**") 103 | .addResourceLocations(location) 104 | .setCachePeriod(cachePeriod) 105 | .resourceChain(useResourceCache) 106 | .addResolver(versionResolver) 107 | .addTransformer(appCacheTransformer); 108 | } 109 | 110 | protected String getApplicationVersion() { 111 | return this.env.acceptsProfiles("development") ? "dev" : this.appVersion; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /server/src/main/java/org/springframework/samples/resources/handlebars/ProfileHelper.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.resources.handlebars; 2 | 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import com.github.jknack.handlebars.Helper; 9 | import com.github.jknack.handlebars.Options; 10 | 11 | /** 12 | * @author Brian Clozel 13 | */ 14 | public class ProfileHelper implements Helper { 15 | 16 | public static final String NAME = "hasProfile"; 17 | 18 | private final Set profiles; 19 | 20 | public ProfileHelper(String[] profiles) { 21 | this.profiles = new HashSet(Arrays.asList(profiles)); 22 | } 23 | 24 | @Override 25 | public CharSequence apply(final Object context, final Options options) 26 | throws IOException { 27 | if (profiles.contains(context)) { 28 | return options.fn(); 29 | } else { 30 | return options.inverse(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /server/src/main/java/org/springframework/samples/resources/handlebars/ResourceUrlHelper.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.resources.handlebars; 2 | 3 | import com.github.jknack.handlebars.Helper; 4 | import com.github.jknack.handlebars.Options; 5 | 6 | import org.springframework.web.servlet.resource.ResourceUrlProvider; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * A Handlebars Helper to help with rendering resource URLs in Mustache templates 12 | * through Spring's 13 | * {@link org.springframework.web.servlet.resource.ResourceUrlProvider}. 14 | * 15 | *

Registered in {@link org.springframework.samples.resources.WebConfig} with 16 | * the name "src" so that the following template syntax will trigger its use: 17 | *

18 |  * href="{{src "/css/main.css"}}"
19 |  * 
20 | */ 21 | public class ResourceUrlHelper implements Helper { 22 | 23 | private final ResourceUrlProvider resourceUrlProvider; 24 | 25 | 26 | public ResourceUrlHelper(ResourceUrlProvider resourceUrlProvider) { 27 | this.resourceUrlProvider = resourceUrlProvider; 28 | } 29 | 30 | @Override 31 | public CharSequence apply(String context, Options options) throws IOException { 32 | return this.resourceUrlProvider.getForLookupPath(context); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | resources: 2 | projectroot: 3 | spring: 4 | view: 5 | prefix: /WEB-INF/jsp/ 6 | suffix: .jsp 7 | groovy: 8 | template: 9 | cache: false 10 | prefix: classpath:/groovy/ 11 | app: 12 | version: de4db33f -------------------------------------------------------------------------------- /server/src/main/resources/groovy/hello.tpl: -------------------------------------------------------------------------------- 1 | yieldUnescaped '' 2 | html { 3 | head { 4 | meta(charset:"utf-8") 5 | meta('http-equiv':"X-UA-Compatible", content:"IE=edge") 6 | meta(name:"viewport", content:"width=device-width") 7 | title('Spring resource handling') 8 | link(href: linkTo.apply('/css/main.css'), type: 'text/css', rel: 'stylesheet') 9 | script(src: linkTo.apply('/lib/system.js'), "") 10 | script(src: linkTo.apply('/config.js'), "") 11 | script(""" 12 | System.config({baseURL: "/${appVersion.apply()}"}); 13 | System.import('app/app'); 14 | """) 15 | } 16 | body { 17 | div(class:'container') { 18 | div(class:'jumbotron') { 19 | h1(id:"greeting", "{insert greeting here}") 20 | } 21 | div(id:"logo", "") 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /server/src/main/resources/handlebars/app.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Spring resource handling 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 |
21 |
22 |

{insert greeting here}

23 |
24 |

Example of HTML5 AppCache manifest

25 | 26 |
27 | 28 | -------------------------------------------------------------------------------- /server/src/main/resources/handlebars/index.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Spring resource handling 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 |
20 |
21 |

{insert greeting here}

22 |
23 | 24 |
25 | 26 | -------------------------------------------------------------------------------- /server/src/main/resources/handlebars/less.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Spring resource handling 7 | 8 | 9 | 10 | 11 | 12 | {{#hasProfile "development"}} 13 | 14 | 17 | {{else}} 18 | 19 | {{/hasProfile}} 20 | 24 | 25 | 26 | 27 |
28 |
29 |

{insert greeting here}

30 |
31 | {{#hasProfile "development"}} 32 |

In dev mode a LESS stylesheet is used (see HTML source of this page)

33 | {{else}} 34 |

In production mode a transpiled version of that stylesheet is used (see HTML source of this page)

35 | {{/hasProfile}} 36 | 37 |
38 | 39 | -------------------------------------------------------------------------------- /server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss} [%thread] %-5level %logger{26} - %msg%n%rEx 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /server/src/main/webapp/WEB-INF/jsp/hellojsp.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 5 | 6 | 7 | 8 | 9 | 10 | Spring resource handling 11 | 12 | 13 | 14 | "> 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 |

{insert greeting here}

28 |
29 |

Spring URL: ${springUrl}

30 |

JSTL URL: ${jstlUrl}

31 | 32 |
33 | 34 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'client', 'server' 2 | --------------------------------------------------------------------------------