From cc2ac546e79ec096860322252ae9970c23bdbc57 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Wed, 20 May 2015 10:21:29 +0200 Subject: [PATCH] #87 - Fix WebJARs resource handling in Starbucks example. --- .../main/java/example/stores/WebConfig.java | 43 +++++++++++++++++++ .../src/main/resources/templates/index.html | 8 ++-- 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 rest/starbucks/src/main/java/example/stores/WebConfig.java diff --git a/rest/starbucks/src/main/java/example/stores/WebConfig.java b/rest/starbucks/src/main/java/example/stores/WebConfig.java new file mode 100644 index 00000000..e8038a9e --- /dev/null +++ b/rest/starbucks/src/main/java/example/stores/WebConfig.java @@ -0,0 +1,43 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package example.stores; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter; + +/** + * Temporarily required manual configuration of resource handling to activate the resource chain handling. + * + * @author Brian Clozel + */ +@Configuration +public class WebConfig extends WebMvcConfigurerAdapter { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/webjars/**").// + addResourceLocations("classpath:/META-INF/resources/webjars/").// + resourceChain(true); + } + + @Bean + public ResourceUrlEncodingFilter resourceUrlEncodingFilter() { + return new ResourceUrlEncodingFilter(); + } +} diff --git a/rest/starbucks/src/main/resources/templates/index.html b/rest/starbucks/src/main/resources/templates/index.html index 8465672f..89e924b6 100644 --- a/rest/starbucks/src/main/resources/templates/index.html +++ b/rest/starbucks/src/main/resources/templates/index.html @@ -6,7 +6,7 @@ - +