Commit 9bc77254 authored by Stephane Nicoll's avatar Stephane Nicoll

Start building against Spring Framework 5 snapshot

This commit enables compatibility build against Spring Framework 5.

The Velocity and Guava support that are deprecated in the 1.x line have
been removed and few other classes contain minor change to comply to non
backward compatible changes in Spring Framework 5.

This commit also switches the required java version to 8.

Closes gh-6977
parent 6643ec37
...@@ -71,11 +71,6 @@ ...@@ -71,11 +71,6 @@
<artifactId>caffeine</artifactId> <artifactId>caffeine</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>com.hazelcast</groupId> <groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId> <artifactId>hazelcast</artifactId>
......
...@@ -31,7 +31,6 @@ import org.springframework.boot.actuate.cache.CaffeineCacheStatisticsProvider; ...@@ -31,7 +31,6 @@ import org.springframework.boot.actuate.cache.CaffeineCacheStatisticsProvider;
import org.springframework.boot.actuate.cache.ConcurrentMapCacheStatisticsProvider; import org.springframework.boot.actuate.cache.ConcurrentMapCacheStatisticsProvider;
import org.springframework.boot.actuate.cache.DefaultCacheStatistics; import org.springframework.boot.actuate.cache.DefaultCacheStatistics;
import org.springframework.boot.actuate.cache.EhCacheStatisticsProvider; import org.springframework.boot.actuate.cache.EhCacheStatisticsProvider;
import org.springframework.boot.actuate.cache.GuavaCacheStatisticsProvider;
import org.springframework.boot.actuate.cache.HazelcastCacheStatisticsProvider; import org.springframework.boot.actuate.cache.HazelcastCacheStatisticsProvider;
import org.springframework.boot.actuate.cache.InfinispanCacheStatisticsProvider; import org.springframework.boot.actuate.cache.InfinispanCacheStatisticsProvider;
import org.springframework.boot.actuate.cache.JCacheCacheStatisticsProvider; import org.springframework.boot.actuate.cache.JCacheCacheStatisticsProvider;
...@@ -45,7 +44,6 @@ import org.springframework.cache.CacheManager; ...@@ -45,7 +44,6 @@ import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.ehcache.EhCacheCache; import org.springframework.cache.ehcache.EhCacheCache;
import org.springframework.cache.guava.GuavaCache;
import org.springframework.cache.jcache.JCacheCache; import org.springframework.cache.jcache.JCacheCache;
import org.springframework.cache.support.NoOpCacheManager; import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -119,17 +117,6 @@ public class CacheStatisticsAutoConfiguration { ...@@ -119,17 +117,6 @@ public class CacheStatisticsAutoConfiguration {
} }
@Configuration
@ConditionalOnClass({ com.google.common.cache.Cache.class, GuavaCache.class })
static class GuavaCacheStatisticsConfiguration {
@Bean
public GuavaCacheStatisticsProvider guavaCacheStatisticsProvider() {
return new GuavaCacheStatisticsProvider();
}
}
@Configuration @Configuration
@ConditionalOnClass(ConcurrentMapCache.class) @ConditionalOnClass(ConcurrentMapCache.class)
static class ConcurrentMapCacheStatisticsConfiguration { static class ConcurrentMapCacheStatisticsConfiguration {
......
/*
* Copyright 2012-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 org.springframework.boot.actuate.cache;
import com.google.common.cache.CacheStats;
import org.springframework.cache.CacheManager;
import org.springframework.cache.guava.GuavaCache;
/**
* {@link CacheStatisticsProvider} implementation for Guava.
*
* @author Stephane Nicoll
* @since 1.3.0
* @deprecated as of 1.5 following the removal of Guava support in Spring Framework 5
*/
@Deprecated
public class GuavaCacheStatisticsProvider implements CacheStatisticsProvider<GuavaCache> {
@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager,
GuavaCache cache) {
DefaultCacheStatistics statistics = new DefaultCacheStatistics();
statistics.setSize(cache.getNativeCache().size());
CacheStats guavaStats = cache.getNativeCache().stats();
if (guavaStats.requestCount() > 0) {
statistics.setHitRatio(guavaStats.hitRate());
statistics.setMissRatio(guavaStats.missRate());
}
return statistics;
}
}
...@@ -126,7 +126,7 @@ public class LogFileMvcEndpoint extends AbstractMvcEndpoint { ...@@ -126,7 +126,7 @@ public class LogFileMvcEndpoint extends AbstractMvcEndpoint {
} }
@Override @Override
protected MediaType getMediaType(Resource resource) { protected MediaType getMediaType(HttpServletRequest request, Resource resource) {
return MediaType.TEXT_PLAIN; return MediaType.TEXT_PLAIN;
} }
......
...@@ -24,7 +24,6 @@ import javax.cache.Caching; ...@@ -24,7 +24,6 @@ import javax.cache.Caching;
import javax.cache.configuration.MutableConfiguration; import javax.cache.configuration.MutableConfiguration;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.cache.CacheBuilder;
import com.hazelcast.cache.HazelcastCachingProvider; import com.hazelcast.cache.HazelcastCachingProvider;
import com.hazelcast.config.Config; import com.hazelcast.config.Config;
import com.hazelcast.config.XmlConfigBuilder; import com.hazelcast.config.XmlConfigBuilder;
...@@ -45,7 +44,6 @@ import org.springframework.cache.caffeine.CaffeineCacheManager; ...@@ -45,7 +44,6 @@ import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager; import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerUtils; import org.springframework.cache.ehcache.EhCacheManagerUtils;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.cache.support.NoOpCacheManager; import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
...@@ -110,14 +108,6 @@ public class CacheStatisticsAutoConfigurationTests { ...@@ -110,14 +108,6 @@ public class CacheStatisticsAutoConfigurationTests {
doTestCoreStatistics(provider, true); doTestCoreStatistics(provider, true);
} }
@Test
public void basicGuavaCacheStatistics() {
load(GuavaConfig.class);
CacheStatisticsProvider provider = this.context
.getBean("guavaCacheStatisticsProvider", CacheStatisticsProvider.class);
doTestCoreStatistics(provider, true);
}
@Test @Test
public void baseCaffeineCacheStatistics() { public void baseCaffeineCacheStatistics() {
load(CaffeineCacheConfig.class); load(CaffeineCacheConfig.class);
...@@ -291,19 +281,6 @@ public class CacheStatisticsAutoConfigurationTests { ...@@ -291,19 +281,6 @@ public class CacheStatisticsAutoConfigurationTests {
} }
@Configuration
static class GuavaConfig {
@Bean
public GuavaCacheManager cacheManager() throws IOException {
GuavaCacheManager cacheManager = new GuavaCacheManager();
cacheManager.setCacheBuilder(CacheBuilder.newBuilder().recordStats());
cacheManager.setCacheNames(Arrays.asList("books", "speakers"));
return cacheManager;
}
}
@Configuration @Configuration
static class ConcurrentMapConfig { static class ConcurrentMapConfig {
......
...@@ -205,11 +205,6 @@ ...@@ -205,11 +205,6 @@
<artifactId>tomcat-jdbc</artifactId> <artifactId>tomcat-jdbc</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.btm</groupId> <groupId>org.codehaus.btm</groupId>
<artifactId>btm</artifactId> <artifactId>btm</artifactId>
......
...@@ -42,7 +42,6 @@ final class CacheConfigurations { ...@@ -42,7 +42,6 @@ final class CacheConfigurations {
mappings.put(CacheType.COUCHBASE, CouchbaseCacheConfiguration.class); mappings.put(CacheType.COUCHBASE, CouchbaseCacheConfiguration.class);
mappings.put(CacheType.REDIS, RedisCacheConfiguration.class); mappings.put(CacheType.REDIS, RedisCacheConfiguration.class);
mappings.put(CacheType.CAFFEINE, CaffeineCacheConfiguration.class); mappings.put(CacheType.CAFFEINE, CaffeineCacheConfiguration.class);
mappings.put(CacheType.GUAVA, GuavaCacheConfiguration.class);
mappings.put(CacheType.SIMPLE, SimpleCacheConfiguration.class); mappings.put(CacheType.SIMPLE, SimpleCacheConfiguration.class);
mappings.put(CacheType.NONE, NoOpCacheConfiguration.class); mappings.put(CacheType.NONE, NoOpCacheConfiguration.class);
MAPPINGS = Collections.unmodifiableMap(mappings); MAPPINGS = Collections.unmodifiableMap(mappings);
......
...@@ -20,7 +20,6 @@ import java.util.ArrayList; ...@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -57,8 +56,6 @@ public class CacheProperties { ...@@ -57,8 +56,6 @@ public class CacheProperties {
private final JCache jcache = new JCache(); private final JCache jcache = new JCache();
private final Guava guava = new Guava();
public CacheType getType() { public CacheType getType() {
return this.type; return this.type;
} }
...@@ -99,10 +96,6 @@ public class CacheProperties { ...@@ -99,10 +96,6 @@ public class CacheProperties {
return this.jcache; return this.jcache;
} }
public Guava getGuava() {
return this.guava;
}
/** /**
* Resolve the config location if set. * Resolve the config location if set.
* @param config the config resource * @param config the config resource
...@@ -256,30 +249,4 @@ public class CacheProperties { ...@@ -256,30 +249,4 @@ public class CacheProperties {
} }
/**
* Guava specific cache properties.
*/
public static class Guava {
/**
* The spec to use to create caches. Check CacheBuilderSpec for more details on
* the spec format.
*/
private String spec;
@Deprecated
@DeprecatedConfigurationProperty(
reason = "Caffeine will supersede the Guava support in Spring Boot 2.0",
replacement = "spring.cache.caffeine.spec")
public String getSpec() {
return this.spec;
}
@Deprecated
public void setSpec(String spec) {
this.spec = spec;
}
}
} }
...@@ -66,12 +66,6 @@ public enum CacheType { ...@@ -66,12 +66,6 @@ public enum CacheType {
*/ */
CAFFEINE, CAFFEINE,
/**
* Guava backed caching.
*/
@Deprecated
GUAVA,
/** /**
* Simple in-memory caching. * Simple in-memory caching.
*/ */
......
/*
* Copyright 2012-2016 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 org.springframework.boot.autoconfigure.cache;
import java.util.List;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheBuilderSpec;
import com.google.common.cache.CacheLoader;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cache.CacheManager;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
* Guava cache configuration.
*
* @author Stephane Nicoll
* @since 1.3.0
*/
@Configuration
@ConditionalOnClass({ CacheBuilder.class, GuavaCacheManager.class })
@ConditionalOnMissingBean(CacheManager.class)
@Conditional(CacheCondition.class)
class GuavaCacheConfiguration {
private final CacheProperties cacheProperties;
private final CacheManagerCustomizers customizers;
private final CacheBuilder<Object, Object> cacheBuilder;
private final CacheBuilderSpec cacheBuilderSpec;
private final CacheLoader<Object, Object> cacheLoader;
GuavaCacheConfiguration(CacheProperties cacheProperties,
CacheManagerCustomizers customizers,
ObjectProvider<CacheBuilder<Object, Object>> cacheBuilderProvider,
ObjectProvider<CacheBuilderSpec> cacheBuilderSpecProvider,
ObjectProvider<CacheLoader<Object, Object>> cacheLoaderProvider) {
this.cacheProperties = cacheProperties;
this.customizers = customizers;
this.cacheBuilder = cacheBuilderProvider.getIfAvailable();
this.cacheBuilderSpec = cacheBuilderSpecProvider.getIfAvailable();
this.cacheLoader = cacheLoaderProvider.getIfAvailable();
}
@Bean
public GuavaCacheManager cacheManager() {
GuavaCacheManager cacheManager = createCacheManager();
List<String> cacheNames = this.cacheProperties.getCacheNames();
if (!CollectionUtils.isEmpty(cacheNames)) {
cacheManager.setCacheNames(cacheNames);
}
return this.customizers.customize(cacheManager);
}
private GuavaCacheManager createCacheManager() {
GuavaCacheManager cacheManager = new GuavaCacheManager();
setCacheBuilder(cacheManager);
if (this.cacheLoader != null) {
cacheManager.setCacheLoader(this.cacheLoader);
}
return cacheManager;
}
private void setCacheBuilder(GuavaCacheManager cacheManager) {
String specification = this.cacheProperties.getGuava().getSpec();
if (StringUtils.hasText(specification)) {
cacheManager.setCacheSpecification(specification);
}
else if (this.cacheBuilderSpec != null) {
cacheManager.setCacheBuilderSpec(this.cacheBuilderSpec);
}
else if (this.cacheBuilder != null) {
cacheManager.setCacheBuilder(this.cacheBuilder);
}
}
}
/*
* Copyright 2012-2016 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 org.springframework.boot.autoconfigure.velocity;
import java.io.IOException;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.servlet.Servlet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.template.TemplateLocation;
import org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.view.velocity.EmbeddedVelocityViewResolver;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ui.velocity.VelocityEngineFactory;
import org.springframework.ui.velocity.VelocityEngineFactoryBean;
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
import org.springframework.web.servlet.view.velocity.VelocityConfig;
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Velocity.
*
* @author Andy Wilkinson
* @author Brian Clozel
* @since 1.1.0
* @deprecated as of 1.4 following the deprecation of Velocity support in Spring Framework
* 4.3
*/
@Configuration
@ConditionalOnClass({ VelocityEngine.class, VelocityEngineFactory.class })
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
@EnableConfigurationProperties(VelocityProperties.class)
@Deprecated
public class VelocityAutoConfiguration {
private static final Log logger = LogFactory.getLog(VelocityAutoConfiguration.class);
private final ApplicationContext applicationContext;
private final VelocityProperties properties;
public VelocityAutoConfiguration(ApplicationContext applicationContext,
VelocityProperties properties) {
this.applicationContext = applicationContext;
this.properties = properties;
}
@PostConstruct
public void checkTemplateLocationExists() {
if (this.properties.isCheckTemplateLocation()) {
TemplateLocation location = new TemplateLocation(
this.properties.getResourceLoaderPath());
if (!location.exists(this.applicationContext)) {
logger.warn("Cannot find template location: " + location
+ " (please add some templates, check your Velocity "
+ "configuration, or set spring.velocity."
+ "checkTemplateLocation=false)");
}
}
}
@Deprecated
protected static class VelocityConfiguration {
@Autowired
protected VelocityProperties properties;
protected void applyProperties(VelocityEngineFactory factory) {
factory.setResourceLoaderPath(this.properties.getResourceLoaderPath());
factory.setPreferFileSystemAccess(this.properties.isPreferFileSystemAccess());
Properties velocityProperties = new Properties();
velocityProperties.setProperty("input.encoding",
this.properties.getCharsetName());
velocityProperties.putAll(this.properties.getProperties());
factory.setVelocityProperties(velocityProperties);
}
}
@Configuration
@ConditionalOnNotWebApplication
@Deprecated
public static class VelocityNonWebConfiguration extends VelocityConfiguration {
@Bean
@ConditionalOnMissingBean
public VelocityEngineFactoryBean velocityConfiguration() {
VelocityEngineFactoryBean velocityEngineFactoryBean = new VelocityEngineFactoryBean();
applyProperties(velocityEngineFactoryBean);
return velocityEngineFactoryBean;
}
}
@Configuration
@ConditionalOnClass(Servlet.class)
@ConditionalOnWebApplication
@Deprecated
public static class VelocityWebConfiguration extends VelocityConfiguration {
@Bean
@ConditionalOnMissingBean(VelocityConfig.class)
public VelocityConfigurer velocityConfigurer() {
VelocityConfigurer configurer = new VelocityConfigurer();
applyProperties(configurer);
return configurer;
}
@Bean
public VelocityEngine velocityEngine(VelocityConfigurer configurer)
throws VelocityException, IOException {
return configurer.getVelocityEngine();
}
@Bean
@ConditionalOnMissingBean(name = "velocityViewResolver")
@ConditionalOnProperty(name = "spring.velocity.enabled", matchIfMissing = true)
public EmbeddedVelocityViewResolver velocityViewResolver() {
EmbeddedVelocityViewResolver resolver = new EmbeddedVelocityViewResolver();
this.properties.applyToViewResolver(resolver);
return resolver;
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledResourceChain
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
return new ResourceUrlEncodingFilter();
}
}
}
/*
* Copyright 2012-2016 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 org.springframework.boot.autoconfigure.velocity;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
/**
* {@link ConfigurationProperties} for configuring Velocity.
*
* @author Andy Wilkinson
* @since 1.1.0
* @deprecated as of 1.4 following the deprecation of Velocity support in Spring Framework
* 4.3
*/
@Deprecated
@ConfigurationProperties(prefix = "spring.velocity")
public class VelocityProperties extends AbstractTemplateViewResolverProperties {
public static final String DEFAULT_RESOURCE_LOADER_PATH = "classpath:/templates/";
public static final String DEFAULT_PREFIX = "";
public static final String DEFAULT_SUFFIX = ".vm";
/**
* Name of the DateTool helper object to expose in the Velocity context of the view.
*/
private String dateToolAttribute;
/**
* Name of the NumberTool helper object to expose in the Velocity context of the view.
*/
private String numberToolAttribute;
/**
* Additional velocity properties.
*/
private Map<String, String> properties = new HashMap<String, String>();
/**
* Template path.
*/
private String resourceLoaderPath = DEFAULT_RESOURCE_LOADER_PATH;
/**
* Velocity Toolbox config location, for example "/WEB-INF/toolbox.xml". Automatically
* loads a Velocity Tools toolbox definition file and expose all defined tools in the
* specified scopes.
*/
private String toolboxConfigLocation;
/**
* Prefer file system access for template loading. File system access enables hot
* detection of template changes.
*/
private boolean preferFileSystemAccess = true;
public VelocityProperties() {
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
}
public String getDateToolAttribute() {
return this.dateToolAttribute;
}
public void setDateToolAttribute(String dateToolAttribute) {
this.dateToolAttribute = dateToolAttribute;
}
public String getNumberToolAttribute() {
return this.numberToolAttribute;
}
public void setNumberToolAttribute(String numberToolAttribute) {
this.numberToolAttribute = numberToolAttribute;
}
public Map<String, String> getProperties() {
return this.properties;
}
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
public String getResourceLoaderPath() {
return this.resourceLoaderPath;
}
public void setResourceLoaderPath(String resourceLoaderPath) {
this.resourceLoaderPath = resourceLoaderPath;
}
public String getToolboxConfigLocation() {
return this.toolboxConfigLocation;
}
public void setToolboxConfigLocation(String toolboxConfigLocation) {
this.toolboxConfigLocation = toolboxConfigLocation;
}
public boolean isPreferFileSystemAccess() {
return this.preferFileSystemAccess;
}
public void setPreferFileSystemAccess(boolean preferFileSystemAccess) {
this.preferFileSystemAccess = preferFileSystemAccess;
}
@Override
public void applyToViewResolver(Object viewResolver) {
super.applyToViewResolver(viewResolver);
VelocityViewResolver resolver = (VelocityViewResolver) viewResolver;
resolver.setToolboxConfigLocation(getToolboxConfigLocation());
resolver.setDateToolAttribute(getDateToolAttribute());
resolver.setNumberToolAttribute(getNumberToolAttribute());
}
}
/*
* Copyright 2012-2016 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 org.springframework.boot.autoconfigure.velocity;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertyResolver;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
/**
* {@link TemplateAvailabilityProvider} that provides availability information for
* Velocity view templates.
*
* @author Andy Wilkinson
* @since 1.1.0
* @deprecated as of 1.4 following the deprecation of Velocity support in Spring Framework
* 4.3
*/
@Deprecated
public class VelocityTemplateAvailabilityProvider
implements TemplateAvailabilityProvider {
@Override
public boolean isTemplateAvailable(String view, Environment environment,
ClassLoader classLoader, ResourceLoader resourceLoader) {
if (ClassUtils.isPresent("org.apache.velocity.app.VelocityEngine", classLoader)) {
PropertyResolver resolver = new RelaxedPropertyResolver(environment,
"spring.velocity.");
String loaderPath = resolver.getProperty("resource-loader-path",
VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH);
String prefix = resolver.getProperty("prefix",
VelocityProperties.DEFAULT_PREFIX);
String suffix = resolver.getProperty("suffix",
VelocityProperties.DEFAULT_SUFFIX);
return resourceLoader.getResource(loaderPath + prefix + view + suffix)
.exists();
}
return false;
}
}
/*
* Copyright 2012-2016 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.
*/
/**
* Auto-configuration for Velocity.
* @deprecated as of 1.4 following the deprecation of Velocity support in Spring Framework
* 4.3
*/
package org.springframework.boot.autoconfigure.velocity;
...@@ -85,7 +85,6 @@ org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration,\ ...@@ -85,7 +85,6 @@ org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration,\
org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration,\ org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration,\
org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration,\ org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration,\
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\ org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
...@@ -114,5 +113,4 @@ org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailability ...@@ -114,5 +113,4 @@ org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailability
org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\ org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\ org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.velocity.VelocityTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.web.JspTemplateAvailabilityProvider org.springframework.boot.autoconfigure.web.JspTemplateAvailabilityProvider
...@@ -27,8 +27,8 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; ...@@ -27,8 +27,8 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration; import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration;
import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.core.io.support.SpringFactoriesLoader;
...@@ -92,12 +92,12 @@ public class EnableAutoConfigurationImportSelectorTests { ...@@ -92,12 +92,12 @@ public class EnableAutoConfigurationImportSelectorTests {
@Test @Test
public void classNamesExclusionsAreApplied() { public void classNamesExclusionsAreApplied() {
configureExclusions(new String[0], configureExclusions(new String[0],
new String[] { VelocityAutoConfiguration.class.getName() }, new String[] { ThymeleafAutoConfiguration.class.getName() },
new String[0]); new String[0]);
String[] imports = this.importSelector.selectImports(this.annotationMetadata); String[] imports = this.importSelector.selectImports(this.annotationMetadata);
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1);
assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions())
.contains(VelocityAutoConfiguration.class.getName()); .contains(ThymeleafAutoConfiguration.class.getName());
} }
@Test @Test
...@@ -114,12 +114,12 @@ public class EnableAutoConfigurationImportSelectorTests { ...@@ -114,12 +114,12 @@ public class EnableAutoConfigurationImportSelectorTests {
public void severalPropertyExclusionsAreApplied() { public void severalPropertyExclusionsAreApplied() {
configureExclusions(new String[0], new String[0], configureExclusions(new String[0], new String[0],
new String[] { FreeMarkerAutoConfiguration.class.getName(), new String[] { FreeMarkerAutoConfiguration.class.getName(),
VelocityAutoConfiguration.class.getName() }); ThymeleafAutoConfiguration.class.getName() });
String[] imports = this.importSelector.selectImports(this.annotationMetadata); String[] imports = this.importSelector.selectImports(this.annotationMetadata);
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2);
assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions())
.contains(FreeMarkerAutoConfiguration.class.getName(), .contains(FreeMarkerAutoConfiguration.class.getName(),
VelocityAutoConfiguration.class.getName()); ThymeleafAutoConfiguration.class.getName());
} }
@Test @Test
...@@ -128,24 +128,24 @@ public class EnableAutoConfigurationImportSelectorTests { ...@@ -128,24 +128,24 @@ public class EnableAutoConfigurationImportSelectorTests {
this.environment.setProperty("spring.autoconfigure.exclude[0]", this.environment.setProperty("spring.autoconfigure.exclude[0]",
FreeMarkerAutoConfiguration.class.getName()); FreeMarkerAutoConfiguration.class.getName());
this.environment.setProperty("spring.autoconfigure.exclude[1]", this.environment.setProperty("spring.autoconfigure.exclude[1]",
VelocityAutoConfiguration.class.getName()); ThymeleafAutoConfiguration.class.getName());
String[] imports = this.importSelector.selectImports(this.annotationMetadata); String[] imports = this.importSelector.selectImports(this.annotationMetadata);
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2);
assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions())
.contains(FreeMarkerAutoConfiguration.class.getName(), .contains(FreeMarkerAutoConfiguration.class.getName(),
VelocityAutoConfiguration.class.getName()); ThymeleafAutoConfiguration.class.getName());
} }
@Test @Test
public void combinedExclusionsAreApplied() { public void combinedExclusionsAreApplied() {
configureExclusions(new String[] { VelocityAutoConfiguration.class.getName() }, configureExclusions(new String[] { GroovyTemplateAutoConfiguration.class.getName() },
new String[] { FreeMarkerAutoConfiguration.class.getName() }, new String[] { FreeMarkerAutoConfiguration.class.getName() },
new String[] { ThymeleafAutoConfiguration.class.getName() }); new String[] { ThymeleafAutoConfiguration.class.getName() });
String[] imports = this.importSelector.selectImports(this.annotationMetadata); String[] imports = this.importSelector.selectImports(this.annotationMetadata);
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 3); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 3);
assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions())
.contains(FreeMarkerAutoConfiguration.class.getName(), .contains(FreeMarkerAutoConfiguration.class.getName(),
VelocityAutoConfiguration.class.getName(), GroovyTemplateAutoConfiguration.class.getName(),
ThymeleafAutoConfiguration.class.getName()); ThymeleafAutoConfiguration.class.getName());
} }
......
...@@ -36,7 +36,6 @@ import com.couchbase.client.spring.cache.CouchbaseCache; ...@@ -36,7 +36,6 @@ import com.couchbase.client.spring.cache.CouchbaseCache;
import com.couchbase.client.spring.cache.CouchbaseCacheManager; import com.couchbase.client.spring.cache.CouchbaseCacheManager;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.CaffeineSpec; import com.github.benmanes.caffeine.cache.CaffeineSpec;
import com.google.common.cache.CacheBuilder;
import com.hazelcast.cache.HazelcastCachingProvider; import com.hazelcast.cache.HazelcastCachingProvider;
import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.spring.cache.HazelcastCacheManager; import com.hazelcast.spring.cache.HazelcastCacheManager;
...@@ -66,8 +65,6 @@ import org.springframework.cache.caffeine.CaffeineCacheManager; ...@@ -66,8 +65,6 @@ import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager; import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.guava.GuavaCache;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheOperationInvocationContext;
import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.cache.jcache.JCacheCacheManager;
...@@ -632,46 +629,6 @@ public class CacheAutoConfigurationTests { ...@@ -632,46 +629,6 @@ public class CacheAutoConfigurationTests {
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "custom1"); assertThat(cacheManager.getCacheNames()).containsOnly("foo", "custom1");
} }
@Test
public void guavaCacheExplicitWithCaches() {
load(DefaultCacheConfiguration.class, "spring.cache.type=guava",
"spring.cache.cacheNames=foo");
GuavaCacheManager cacheManager = validateCacheManager(GuavaCacheManager.class);
Cache foo = cacheManager.getCache("foo");
foo.get("1");
// See next tests: no spec given so stats should be disabled
assertThat(((GuavaCache) foo).getNativeCache().stats().missCount()).isEqualTo(0L);
}
@Test
public void guavaCacheWithCustomizers() {
testCustomizers(DefaultCacheAndCustomizersConfiguration.class, "guava",
"allCacheManagerCustomizer", "guavaCacheManagerCustomizer");
}
@Test
public void guavaCacheExplicitWithSpec() {
load(DefaultCacheConfiguration.class, "spring.cache.type=guava",
"spring.cache.guava.spec=recordStats", "spring.cache.cacheNames[0]=foo",
"spring.cache.cacheNames[1]=bar");
validateGuavaCacheWithStats();
}
@Test
public void guavaCacheExplicitWithCacheBuilder() {
load(GuavaCacheBuilderConfiguration.class, "spring.cache.type=guava",
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
validateGuavaCacheWithStats();
}
private void validateGuavaCacheWithStats() {
GuavaCacheManager cacheManager = validateCacheManager(GuavaCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
Cache foo = cacheManager.getCache("foo");
foo.get("1");
assertThat(((GuavaCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
}
@Test @Test
public void caffeineCacheWithExplicitCaches() { public void caffeineCacheWithExplicitCaches() {
load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine", load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine",
...@@ -995,17 +952,6 @@ public class CacheAutoConfigurationTests { ...@@ -995,17 +952,6 @@ public class CacheAutoConfigurationTests {
} }
@Configuration
@EnableCaching
static class GuavaCacheBuilderConfiguration {
@Bean
CacheBuilder<Object, Object> cacheBuilder() {
return CacheBuilder.newBuilder().recordStats();
}
}
@Configuration @Configuration
@EnableCaching @EnableCaching
static class CaffeineCacheBuilderConfiguration { static class CaffeineCacheBuilderConfiguration {
...@@ -1079,12 +1025,6 @@ public class CacheAutoConfigurationTests { ...@@ -1079,12 +1025,6 @@ public class CacheAutoConfigurationTests {
}; };
} }
@Bean
public CacheManagerCustomizer<GuavaCacheManager> guavaCacheManagerCustomizer() {
return new CacheManagerTestCustomizer<GuavaCacheManager>() {
};
}
@Bean @Bean
public CacheManagerCustomizer<CaffeineCacheManager> caffeineCacheManagerCustomizer() { public CacheManagerCustomizer<CaffeineCacheManager> caffeineCacheManagerCustomizer() {
return new CacheManagerTestCustomizer<CaffeineCacheManager>() { return new CacheManagerTestCustomizer<CaffeineCacheManager>() {
......
/*
* Copyright 2012-2016 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 org.springframework.boot.autoconfigure.velocity;
import java.io.File;
import java.io.StringWriter;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.web.servlet.view.velocity.EmbeddedVelocityViewResolver;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
/**
* Tests for {@link VelocityAutoConfiguration}.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
@SuppressWarnings("deprecation")
public class VelocityAutoConfigurationTests {
@Rule
public OutputCapture output = new OutputCapture();
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
@Before
public void setupContext() {
this.context.setServletContext(new MockServletContext());
}
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void defaultConfiguration() {
registerAndRefreshContext();
assertThat(this.context.getBean(VelocityViewResolver.class)).isNotNull();
assertThat(this.context.getBean(VelocityConfigurer.class)).isNotNull();
}
@Test
public void nonExistentTemplateLocation() {
registerAndRefreshContext(
"spring.velocity.resourceLoaderPath:" + "classpath:/does-not-exist/");
this.output.expect(containsString("Cannot find template location"));
}
@Test
public void emptyTemplateLocation() {
new File("target/test-classes/templates/empty-directory").mkdir();
registerAndRefreshContext("spring.velocity.resourceLoaderPath:"
+ "classpath:/templates/empty-directory/");
}
@Test
public void defaultViewResolution() throws Exception {
registerAndRefreshContext();
MockHttpServletResponse response = render("home");
String result = response.getContentAsString();
assertThat(result).contains("home");
assertThat(response.getContentType()).isEqualTo("text/html;charset=UTF-8");
}
@Test
public void customContentType() throws Exception {
registerAndRefreshContext("spring.velocity.contentType:application/json");
MockHttpServletResponse response = render("home");
String result = response.getContentAsString();
assertThat(result).contains("home");
assertThat(response.getContentType()).isEqualTo("application/json;charset=UTF-8");
}
@Test
public void customCharset() throws Exception {
registerAndRefreshContext("spring.velocity.charset:ISO-8859-1");
assertThat(this.context.getBean(VelocityConfigurer.class).getVelocityEngine()
.getProperty("input.encoding")).isEqualTo("ISO-8859-1");
}
@Test
public void customPrefix() throws Exception {
registerAndRefreshContext("spring.velocity.prefix:prefix/");
MockHttpServletResponse response = render("prefixed");
String result = response.getContentAsString();
assertThat(result).contains("prefixed");
}
@Test
public void customSuffix() throws Exception {
registerAndRefreshContext("spring.velocity.suffix:.freemarker");
MockHttpServletResponse response = render("suffixed");
String result = response.getContentAsString();
assertThat(result).contains("suffixed");
}
@Test
public void customTemplateLoaderPath() throws Exception {
registerAndRefreshContext(
"spring.velocity.resourceLoaderPath:classpath:/custom-templates/");
MockHttpServletResponse response = render("custom");
String result = response.getContentAsString();
assertThat(result).contains("custom");
}
@Test
public void disableCache() {
registerAndRefreshContext("spring.velocity.cache:false");
assertThat(this.context.getBean(VelocityViewResolver.class).getCacheLimit())
.isEqualTo(0);
}
@Test
public void customVelocitySettings() {
registerAndRefreshContext(
"spring.velocity.properties.directive.parse.max.depth:10");
assertThat(this.context.getBean(VelocityConfigurer.class).getVelocityEngine()
.getProperty("directive.parse.max.depth")).isEqualTo("10");
}
@Test
public void renderTemplate() throws Exception {
registerAndRefreshContext();
VelocityConfigurer velocity = this.context.getBean(VelocityConfigurer.class);
StringWriter writer = new StringWriter();
Template template = velocity.getVelocityEngine().getTemplate("message.vm");
template.process();
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("greeting", "Hello World");
template.merge(velocityContext, writer);
assertThat(writer.toString()).contains("Hello World");
}
@Test
public void renderNonWebAppTemplate() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
VelocityAutoConfiguration.class);
try {
VelocityEngine velocity = context.getBean(VelocityEngine.class);
StringWriter writer = new StringWriter();
Template template = velocity.getTemplate("message.vm");
template.process();
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("greeting", "Hello World");
template.merge(velocityContext, writer);
assertThat(writer.toString()).contains("Hello World");
}
finally {
context.close();
}
}
@Test
public void usesEmbeddedVelocityViewResolver() {
registerAndRefreshContext("spring.velocity.toolbox:/toolbox.xml");
VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
assertThat(resolver).isInstanceOf(EmbeddedVelocityViewResolver.class);
}
@Test
public void registerResourceHandlingFilterDisabledByDefault() throws Exception {
registerAndRefreshContext();
assertThat(this.context.getBeansOfType(ResourceUrlEncodingFilter.class))
.isEmpty();
}
@Test
public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled()
throws Exception {
registerAndRefreshContext("spring.resources.chain.enabled:true");
assertThat(this.context.getBean(ResourceUrlEncodingFilter.class)).isNotNull();
}
@Test
public void allowSessionOverride() {
registerAndRefreshContext("spring.velocity.allow-session-override:true");
AbstractTemplateViewResolver viewResolver = this.context
.getBean(VelocityViewResolver.class);
assertThat(viewResolver).extracting("allowSessionOverride").containsExactly(true);
}
private void registerAndRefreshContext(String... env) {
EnvironmentTestUtils.addEnvironment(this.context, env);
this.context.register(VelocityAutoConfiguration.class);
this.context.refresh();
}
public String getGreeting() {
return "Hello World";
}
private MockHttpServletResponse render(String viewName) throws Exception {
VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
View view = resolver.resolveViewName(viewName, Locale.UK);
assertThat(view).isNotNull();
HttpServletRequest request = new MockHttpServletRequest();
request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
this.context);
MockHttpServletResponse response = new MockHttpServletResponse();
view.render(null, request, response);
return response;
}
}
/*
* Copyright 2012-2016 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 org.springframework.boot.autoconfigure.velocity;
import org.junit.Test;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link VelocityTemplateAvailabilityProvider}.
*
* @author Andy Wilkinson
*/
@SuppressWarnings("deprecation")
public class VelocityTemplateAvailabilityProviderTests {
private final TemplateAvailabilityProvider provider = new VelocityTemplateAvailabilityProvider();
private final ResourceLoader resourceLoader = new DefaultResourceLoader();
private final MockEnvironment environment = new MockEnvironment();
@Test
public void availabilityOfTemplateInDefaultLocation() {
assertThat(this.provider.isTemplateAvailable("home", this.environment,
getClass().getClassLoader(), this.resourceLoader)).isTrue();
}
@Test
public void availabilityOfTemplateThatDoesNotExist() {
assertThat(this.provider.isTemplateAvailable("whatever", this.environment,
getClass().getClassLoader(), this.resourceLoader)).isFalse();
}
@Test
public void availabilityOfTemplateWithCustomLoaderPath() {
this.environment.setProperty("spring.velocity.resourceLoaderPath",
"classpath:/custom-templates/");
assertThat(this.provider.isTemplateAvailable("custom", this.environment,
getClass().getClassLoader(), this.resourceLoader)).isTrue();
}
@Test
public void availabilityOfTemplateWithCustomPrefix() {
this.environment.setProperty("spring.velocity.prefix", "prefix/");
assertThat(this.provider.isTemplateAvailable("prefixed", this.environment,
getClass().getClassLoader(), this.resourceLoader)).isTrue();
}
@Test
public void availabilityOfTemplateWithCustomSuffix() {
this.environment.setProperty("spring.velocity.suffix", ".freemarker");
assertThat(this.provider.isTemplateAvailable("suffixed", this.environment,
getClass().getClassLoader(), this.resourceLoader)).isTrue();
}
}
...@@ -29,7 +29,9 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter; ...@@ -29,7 +29,9 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.ResourceHttpMessageConverter; import org.springframework.http.converter.ResourceHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter;
...@@ -61,6 +63,8 @@ public class HttpMessageConvertersTests { ...@@ -61,6 +63,8 @@ public class HttpMessageConvertersTests {
SourceHttpMessageConverter.class, SourceHttpMessageConverter.class,
AllEncompassingFormHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class,
MappingJackson2HttpMessageConverter.class, MappingJackson2HttpMessageConverter.class,
MappingJackson2SmileHttpMessageConverter.class,
MappingJackson2CborHttpMessageConverter.class,
MappingJackson2XmlHttpMessageConverter.class); MappingJackson2XmlHttpMessageConverter.class);
} }
...@@ -131,7 +135,9 @@ public class HttpMessageConvertersTests { ...@@ -131,7 +135,9 @@ public class HttpMessageConvertersTests {
StringHttpMessageConverter.class, ResourceHttpMessageConverter.class, StringHttpMessageConverter.class, ResourceHttpMessageConverter.class,
SourceHttpMessageConverter.class, SourceHttpMessageConverter.class,
AllEncompassingFormHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class,
MappingJackson2HttpMessageConverter.class); MappingJackson2HttpMessageConverter.class,
MappingJackson2SmileHttpMessageConverter.class,
MappingJackson2CborHttpMessageConverter.class);
} }
@Test @Test
...@@ -158,7 +164,8 @@ public class HttpMessageConvertersTests { ...@@ -158,7 +164,8 @@ public class HttpMessageConvertersTests {
assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class, assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class,
StringHttpMessageConverter.class, ResourceHttpMessageConverter.class, StringHttpMessageConverter.class, ResourceHttpMessageConverter.class,
SourceHttpMessageConverter.class, SourceHttpMessageConverter.class,
MappingJackson2HttpMessageConverter.class); MappingJackson2HttpMessageConverter.class,
MappingJackson2SmileHttpMessageConverter.class);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
......
...@@ -144,18 +144,18 @@ ...@@ -144,18 +144,18 @@
<snakeyaml.version>1.17</snakeyaml.version> <snakeyaml.version>1.17</snakeyaml.version>
<solr.version>5.5.3</solr.version> <solr.version>5.5.3</solr.version>
<spock.version>1.0-groovy-2.4</spock.version> <spock.version>1.0-groovy-2.4</spock.version>
<spring.version>4.3.3.RELEASE</spring.version> <spring.version>5.0.0.BUILD-SNAPSHOT</spring.version>
<spring-amqp.version>1.6.2.RELEASE</spring-amqp.version> <spring-amqp.version>1.6.2.RELEASE</spring-amqp.version>
<spring-cloud-connectors.version>1.2.3.RELEASE</spring-cloud-connectors.version> <spring-cloud-connectors.version>1.2.3.RELEASE</spring-cloud-connectors.version>
<spring-batch.version>3.0.7.RELEASE</spring-batch.version> <spring-batch.version>3.0.7.RELEASE</spring-batch.version>
<spring-data-releasetrain.version>Hopper-SR3</spring-data-releasetrain.version> <spring-data-releasetrain.version>Hopper-SR3</spring-data-releasetrain.version>
<spring-hateoas.version>0.20.0.RELEASE</spring-hateoas.version> <spring-hateoas.version>0.21.0.BUILD-SNAPSHOT</spring-hateoas.version>
<spring-integration.version>4.3.2.RELEASE</spring-integration.version> <spring-integration.version>4.3.2.RELEASE</spring-integration.version>
<spring-integration-java-dsl.version>1.1.3.RELEASE</spring-integration-java-dsl.version> <spring-integration-java-dsl.version>1.1.3.RELEASE</spring-integration-java-dsl.version>
<spring-loaded.version>1.2.6.RELEASE</spring-loaded.version> <spring-loaded.version>1.2.6.RELEASE</spring-loaded.version>
<spring-mobile.version>1.1.5.RELEASE</spring-mobile.version> <spring-mobile.version>1.1.5.RELEASE</spring-mobile.version>
<spring-plugin.version>1.2.0.RELEASE</spring-plugin.version> <spring-plugin.version>1.2.0.RELEASE</spring-plugin.version>
<spring-restdocs.version>1.1.2.RELEASE</spring-restdocs.version> <spring-restdocs.version>1.2.0.BUILD-SNAPSHOT</spring-restdocs.version>
<spring-retry.version>1.1.4.RELEASE</spring-retry.version> <spring-retry.version>1.1.4.RELEASE</spring-retry.version>
<spring-security.version>4.1.3.RELEASE</spring-security.version> <spring-security.version>4.1.3.RELEASE</spring-security.version>
<spring-security-jwt.version>1.0.5.RELEASE</spring-security-jwt.version> <spring-security-jwt.version>1.0.5.RELEASE</spring-security-jwt.version>
...@@ -177,8 +177,6 @@ ...@@ -177,8 +177,6 @@
<thymeleaf-extras-java8time.version>2.1.0.RELEASE</thymeleaf-extras-java8time.version> <thymeleaf-extras-java8time.version>2.1.0.RELEASE</thymeleaf-extras-java8time.version>
<tomcat.version>8.5.5</tomcat.version> <tomcat.version>8.5.5</tomcat.version>
<undertow.version>1.3.25.Final</undertow.version> <undertow.version>1.3.25.Final</undertow.version>
<velocity.version>1.7</velocity.version>
<velocity-tools.version>2.0</velocity-tools.version>
<webjars-hal-browser.version>9f96c74</webjars-hal-browser.version> <webjars-hal-browser.version>9f96c74</webjars-hal-browser.version>
<webjars-locator.version>0.32</webjars-locator.version> <webjars-locator.version>0.32</webjars-locator.version>
<wsdl4j.version>1.6.3</wsdl4j.version> <wsdl4j.version>1.6.3</wsdl4j.version>
...@@ -499,11 +497,6 @@ ...@@ -499,11 +497,6 @@
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version> <version>2.0.0.BUILD-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
...@@ -1353,22 +1346,6 @@ ...@@ -1353,22 +1346,6 @@
<artifactId>tomcat-jsp-api</artifactId> <artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version> <version>${tomcat.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>${velocity.version}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>${velocity-tools.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.aspectj</groupId> <groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId> <artifactId>aspectjrt</artifactId>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
</organization> </organization>
<properties> <properties>
<main.basedir>${basedir}/../..</main.basedir> <main.basedir>${basedir}/../..</main.basedir>
<tomee.version>1.7.4</tomee.version> <tomee.version>7.0.1</tomee.version>
<cargo.container.id>tomee1x</cargo.container.id> <cargo.container.id>tomee1x</cargo.container.id>
<cargo.container.url> <cargo.container.url>
https://www.apache.org/dist/tomee/tomee-${tomee.version}/apache-tomee-${tomee.version}-webprofile.zip https://www.apache.org/dist/tomee/tomee-${tomee.version}/apache-tomee-${tomee.version}-webprofile.zip
......
...@@ -46,7 +46,6 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro ...@@ -46,7 +46,6 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
properties.put("spring.thymeleaf.cache", "false"); properties.put("spring.thymeleaf.cache", "false");
properties.put("spring.freemarker.cache", "false"); properties.put("spring.freemarker.cache", "false");
properties.put("spring.groovy.template.cache", "false"); properties.put("spring.groovy.template.cache", "false");
properties.put("spring.velocity.cache", "false");
properties.put("spring.mustache.cache", "false"); properties.put("spring.mustache.cache", "false");
properties.put("server.session.persistent", "true"); properties.put("server.session.persistent", "true");
properties.put("spring.h2.console.enabled", "true"); properties.put("spring.h2.console.enabled", "true");
......
...@@ -304,16 +304,6 @@ ...@@ -304,16 +304,6 @@
<artifactId>tomcat-jdbc</artifactId> <artifactId>tomcat-jdbc</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
......
...@@ -71,7 +71,6 @@ content into your application; rather pick only the properties that you need. ...@@ -71,7 +71,6 @@ content into your application; rather pick only the properties that you need.
spring.cache.caffeine.spec= # The spec to use to create caches. Check CaffeineSpec for more details on the spec format. spring.cache.caffeine.spec= # The spec to use to create caches. Check CaffeineSpec for more details on the spec format.
spring.cache.couchbase.expiration=0 # Entry expiration in milliseconds. By default the entries never expire. spring.cache.couchbase.expiration=0 # Entry expiration in milliseconds. By default the entries never expire.
spring.cache.ehcache.config= # The location of the configuration file to use to initialize EhCache. spring.cache.ehcache.config= # The location of the configuration file to use to initialize EhCache.
spring.cache.guava.spec= # The spec to use to create caches. Check CacheBuilderSpec for more details on the spec format.
spring.cache.hazelcast.config= # The location of the configuration file to use to initialize Hazelcast. spring.cache.hazelcast.config= # The location of the configuration file to use to initialize Hazelcast.
spring.cache.infinispan.config= # The location of the configuration file to use to initialize Infinispan. spring.cache.infinispan.config= # The location of the configuration file to use to initialize Infinispan.
spring.cache.jcache.config= # The location of the configuration file to use to initialize the cache manager. spring.cache.jcache.config= # The location of the configuration file to use to initialize the cache manager.
...@@ -406,28 +405,6 @@ content into your application; rather pick only the properties that you need. ...@@ -406,28 +405,6 @@ content into your application; rather pick only the properties that you need.
spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain. spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain.
spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved. spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved.
# VELOCITY TEMPLATES ({sc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{sc-ext}[VelocityAutoConfiguration])
spring.velocity.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.velocity.allow-session-override=false # Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.velocity.cache= # Enable template caching.
spring.velocity.charset=UTF-8 # Template encoding.
spring.velocity.check-template-location=true # Check that the templates location exists.
spring.velocity.content-type=text/html # Content-Type value.
spring.velocity.date-tool-attribute= # Name of the DateTool helper object to expose in the Velocity context of the view.
spring.velocity.enabled=true # Enable MVC view resolution for this technology.
spring.velocity.expose-request-attributes=false # Set whether all request attributes should be added to the model prior to merging with the template.
spring.velocity.expose-session-attributes=false # Set whether all HttpSession attributes should be added to the model prior to merging with the template.
spring.velocity.expose-spring-macro-helpers=true # Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".
spring.velocity.number-tool-attribute= # Name of the NumberTool helper object to expose in the Velocity context of the view.
spring.velocity.prefer-file-system-access=true # Prefer file system access for template loading. File system access enables hot detection of template changes.
spring.velocity.prefix= # Prefix that gets prepended to view names when building a URL.
spring.velocity.properties.*= # Additional velocity properties.
spring.velocity.request-context-attribute= # Name of the RequestContext attribute for all views.
spring.velocity.resource-loader-path=classpath:/templates/ # Template path.
spring.velocity.suffix=.vm # Suffix that gets appended to view names when building a URL.
spring.velocity.toolbox-config-location= # Velocity Toolbox config location. For instance `/WEB-INF/toolbox.xml`
spring.velocity.view-names= # White list of view names that can be resolved.
# SPRING WEB SERVICES ({sc-spring-boot-autoconfigure}/webservices/WebServicesProperties.{sc-ext}[WebServicesProperties]) # SPRING WEB SERVICES ({sc-spring-boot-autoconfigure}/webservices/WebServicesProperties.{sc-ext}[WebServicesProperties])
spring.webservices.path=/services # Path that serves as the base URI for the services. spring.webservices.path=/services # Path that serves as the base URI for the services.
spring.webservices.servlet.init= # Servlet init parameters to pass to Spring Web Services. spring.webservices.servlet.init= # Servlet init parameters to pass to Spring Web Services.
......
...@@ -1417,41 +1417,11 @@ added. ...@@ -1417,41 +1417,11 @@ added.
suffix (externalized to `spring.groovy.template.prefix` and suffix (externalized to `spring.groovy.template.prefix` and
`spring.groovy.template.suffix`, defaults '`classpath:/templates/`' and '`.tpl`' `spring.groovy.template.suffix`, defaults '`classpath:/templates/`' and '`.tpl`'
respectively). It can be overridden by providing a bean of the same name. respectively). It can be overridden by providing a bean of the same name.
* If you use Velocity you will also have a `VelocityViewResolver` with id '`velocityViewResolver`'.
It looks for resources in a loader path (externalized to `spring.velocity.resourceLoaderPath`,
default '`classpath:/templates/`') by surrounding the view name with a prefix and suffix
(externalized to `spring.velocity.prefix` and `spring.velocity.suffix`, with empty and '`.vm`'
defaults respectively). It can be overridden by providing a bean of the same name.
Check out {sc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{sc-ext}[`WebMvcAutoConfiguration`], Check out {sc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{sc-ext}[`WebMvcAutoConfiguration`],
{sc-spring-boot-autoconfigure}/thymeleaf/ThymeleafAutoConfiguration.{sc-ext}[`ThymeleafAutoConfiguration`], {sc-spring-boot-autoconfigure}/thymeleaf/ThymeleafAutoConfiguration.{sc-ext}[`ThymeleafAutoConfiguration`],
{sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[`FreeMarkerAutoConfiguration`], {sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[`FreeMarkerAutoConfiguration`],
{sc-spring-boot-autoconfigure}/groovy/template/GroovyTemplateAutoConfiguration.{sc-ext}[`GroovyTemplateAutoConfiguration`] and {sc-spring-boot-autoconfigure}/groovy/template/GroovyTemplateAutoConfiguration.{sc-ext}[`GroovyTemplateAutoConfiguration`]
{sc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{sc-ext}[`VelocityAutoConfiguration`]
[[howto-customize-view-resolvers-velocity]]
=== Velocity
By default, Spring Boot configures a `VelocityViewResolver`. If you need a
`VelocityLayoutViewResolver` instead, you can easily configure your own by creating a bean
with name `velocityViewResolver`. You can also inject the `VelocityProperties` instance to
apply the base defaults to your custom view resolver.
The following example replaces the auto-configured velocity view resolver with a
`VelocityLayoutViewResolver` defining a customized `layoutUrl` and all settings that would
have been applied from the auto-configuration:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@Bean(name = "velocityViewResolver")
public VelocityLayoutViewResolver velocityViewResolver(VelocityProperties properties) {
VelocityLayoutViewResolver resolver = new VelocityLayoutViewResolver();
properties.applyToViewResolver(resolver);
resolver.setLayoutUrl("layout/default.vm");
return resolver;
}
----
...@@ -2370,14 +2340,6 @@ for other Groovy customization options. ...@@ -2370,14 +2340,6 @@ for other Groovy customization options.
[[howto-reload-velocity-content]]
==== Velocity templates
If you are using Velocity, then set `spring.velocity.cache` to `false`. See
{sc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{sc-ext}[`VelocityAutoConfiguration`]
for other Velocity customization options.
[[howto-reload-fast-restart]] [[howto-reload-fast-restart]]
=== Fast application restarts === Fast application restarts
The `spring-boot-devtools` module includes support for automatic application restarts. The `spring-boot-devtools` module includes support for automatic application restarts.
......
...@@ -1067,7 +1067,7 @@ is prefixed by the name of the `CacheManager` bean. ...@@ -1067,7 +1067,7 @@ is prefixed by the name of the `CacheManager` bean.
It is possible to override part or all of those defaults by registering a bean with a It is possible to override part or all of those defaults by registering a bean with a
customized version of `CachePublicMetrics`. By default, Spring Boot provides cache customized version of `CachePublicMetrics`. By default, Spring Boot provides cache
statistics for EhCache, Hazelcast, Infinispan, JCache and Guava. You can add additional statistics for EhCache, Hazelcast, Infinispan, JCache and Caffeine. You can add additional
`CacheStatisticsProvider` beans if your favorite caching library isn't supported out of `CacheStatisticsProvider` beans if your favorite caching library isn't supported out of
the box. See `CacheStatisticsAutoConfiguration` for examples. the box. See `CacheStatisticsAutoConfiguration` for examples.
......
...@@ -1774,7 +1774,7 @@ solution for all static resources, effectively adding a content hash in URLs, su ...@@ -1774,7 +1774,7 @@ solution for all static resources, effectively adding a content hash in URLs, su
---- ----
NOTE: Links to resources are rewritten at runtime in template, thanks to a NOTE: Links to resources are rewritten at runtime in template, thanks to a
`ResourceUrlEncodingFilter`, auto-configured for Thymeleaf, Velocity and FreeMarker. You `ResourceUrlEncodingFilter`, auto-configured for Thymeleaf and FreeMarker. You
should manually declare this filter when using JSPs. Other template engines aren't should manually declare this filter when using JSPs. Other template engines aren't
automatically supported right now, but can be with custom template macros/helpers and the automatically supported right now, but can be with custom template macros/helpers and the
use of the use of the
...@@ -1821,7 +1821,7 @@ will automatically configure Spring MVC to use it. ...@@ -1821,7 +1821,7 @@ will automatically configure Spring MVC to use it.
[[boot-features-spring-mvc-template-engines]] [[boot-features-spring-mvc-template-engines]]
==== Template engines ==== Template engines
As well as REST web services, you can also use Spring MVC to serve dynamic HTML content. As well as REST web services, you can also use Spring MVC to serve dynamic HTML content.
Spring MVC supports a variety of templating technologies including Velocity, FreeMarker Spring MVC supports a variety of templating technologies including FreeMarker
and JSPs. Many other templating engines also ship their own Spring MVC integrations. and JSPs. Many other templating engines also ship their own Spring MVC integrations.
Spring Boot includes auto-configuration support for the following templating engines: Spring Boot includes auto-configuration support for the following templating engines:
...@@ -1829,7 +1829,6 @@ Spring Boot includes auto-configuration support for the following templating eng ...@@ -1829,7 +1829,6 @@ Spring Boot includes auto-configuration support for the following templating eng
* http://freemarker.org/docs/[FreeMarker] * http://freemarker.org/docs/[FreeMarker]
* http://docs.groovy-lang.org/docs/next/html/documentation/template-engines.html#_the_markuptemplateengine[Groovy] * http://docs.groovy-lang.org/docs/next/html/documentation/template-engines.html#_the_markuptemplateengine[Groovy]
* http://www.thymeleaf.org[Thymeleaf] * http://www.thymeleaf.org[Thymeleaf]
* http://velocity.apache.org[Velocity] (deprecated in 1.4)
* http://mustache.github.io/[Mustache] * http://mustache.github.io/[Mustache]
TIP: JSPs should be avoided if possible, there are several TIP: JSPs should be avoided if possible, there are several
...@@ -3799,7 +3798,6 @@ providers (in this order): ...@@ -3799,7 +3798,6 @@ providers (in this order):
* <<boot-features-caching-provider-couchbase,Couchbase>> * <<boot-features-caching-provider-couchbase,Couchbase>>
* <<boot-features-caching-provider-redis,Redis>> * <<boot-features-caching-provider-redis,Redis>>
* <<boot-features-caching-provider-caffeine,Caffeine>> * <<boot-features-caching-provider-caffeine,Caffeine>>
* <<boot-features-caching-provider-guava,Guava>> (deprecated)
* <<boot-features-caching-provider-simple,Simple>> * <<boot-features-caching-provider-simple,Simple>>
TIP: It is also possible to _force_ the cache provider to use via the `spring.cache.type` TIP: It is also possible to _force_ the cache provider to use via the `spring.cache.type`
...@@ -3992,10 +3990,10 @@ recommend to keep this setting enabled if you create your own `RedisCacheManager ...@@ -3992,10 +3990,10 @@ recommend to keep this setting enabled if you create your own `RedisCacheManager
[[boot-features-caching-provider-caffeine]] [[boot-features-caching-provider-caffeine]]
==== Caffeine ==== Caffeine
Caffeine is a Java 8 rewrite of Guava’s cache and will supersede the Guava support in Caffeine is a Java 8 rewrite of Guava’s cache that supersede the Guava support. If
Spring Boot 2.0. If Caffeine is present, a `CaffeineCacheManager` is auto-configured. Caffeine is present, a `CaffeineCacheManager` is auto-configured. Caches can be created
Caches can be created on startup using the `spring.cache.cache-names` property and on startup using the `spring.cache.cache-names` property and customized by one of the
customized by one of the following (in this order): following (in this order):
1. A cache spec defined by `spring.cache.caffeine.spec` 1. A cache spec defined by `spring.cache.caffeine.spec`
2. A `com.github.benmanes.caffeine.cache.CaffeineSpec` bean is defined 2. A `com.github.benmanes.caffeine.cache.CaffeineSpec` bean is defined
...@@ -4018,33 +4016,6 @@ auto-configuration. ...@@ -4018,33 +4016,6 @@ auto-configuration.
[[boot-features-caching-provider-guava]]
==== Guava (deprecated)
If Guava is present, a `GuavaCacheManager` is auto-configured. Caches can be created
on startup using the `spring.cache.cache-names` property and customized by one of the
following (in this order):
1. A cache spec defined by `spring.cache.guava.spec`
2. A `com.google.common.cache.CacheBuilderSpec` bean is defined
3. A `com.google.common.cache.CacheBuilder` bean is defined
For instance, the following configuration creates a `foo` and `bar` caches with a maximum
size of 500 and a _time to live_ of 10 minutes
[source,properties,indent=0]
----
spring.cache.cache-names=foo,bar
spring.cache.guava.spec=maximumSize=500,expireAfterAccess=600s
----
Besides, if a `com.google.common.cache.CacheLoader` bean is defined, it is automatically
associated to the `GuavaCacheManager`. Since the `CacheLoader` is going to be associated
to _all_ caches managed by the cache manager, it must be defined as
`CacheLoader<Object, Object>`. Any other generic type will be ignored by the
auto-configuration.
[[boot-features-caching-provider-simple]] [[boot-features-caching-provider-simple]]
==== Simple ==== Simple
If none of these options worked out, a simple implementation using `ConcurrentHashMap` If none of these options worked out, a simple implementation using `ConcurrentHashMap`
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<properties> <properties>
<main.basedir>..</main.basedir> <main.basedir>..</main.basedir>
<disable.checks>false</disable.checks> <disable.checks>false</disable.checks>
<java.version>1.6</java.version> <java.version>1.8</java.version>
<aether.version>1.0.2.v20150114</aether.version> <aether.version>1.0.2.v20150114</aether.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
...@@ -47,11 +47,6 @@ ...@@ -47,11 +47,6 @@
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
<version>1.2.17</version> <version>1.2.17</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.squareup.okhttp</groupId> <groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>
......
...@@ -222,9 +222,6 @@ The following sample applications are provided: ...@@ -222,9 +222,6 @@ The following sample applications are provided:
| link:spring-boot-sample-undertow-ssl[spring-boot-sample-undertow-ssl] | link:spring-boot-sample-undertow-ssl[spring-boot-sample-undertow-ssl]
| Embedded Undertow configured to use SSL | Embedded Undertow configured to use SSL
| link:spring-boot-sample-velocity[spring-boot-sample-velocity]
| Non-web application that uses Velocity templates
| link:spring-boot-sample-war[spring-boot-sample-war] | link:spring-boot-sample-war[spring-boot-sample-war]
| Web application packaged as a war file | Web application packaged as a war file
...@@ -261,9 +258,6 @@ The following sample applications are provided: ...@@ -261,9 +258,6 @@ The following sample applications are provided:
| link:spring-boot-sample-web-ui[spring-boot-sample-web-ui] | link:spring-boot-sample-web-ui[spring-boot-sample-web-ui]
| Web application with a basic UI built using Bootstrap and JQuery | Web application with a basic UI built using Bootstrap and JQuery
| link:spring-boot-sample-web-velocity[spring-boot-sample-web-velocity]
| Web application that uses Velocity templates
| link:spring-boot-sample-webservices[spring-boot-sample-webservices] | link:spring-boot-sample-webservices[spring-boot-sample-webservices]
| Simple contract-first SOAP web service with Spring Web Services | Simple contract-first SOAP web service with Spring Web Services
......
...@@ -93,7 +93,6 @@ ...@@ -93,7 +93,6 @@
<module>spring-boot-sample-traditional</module> <module>spring-boot-sample-traditional</module>
<module>spring-boot-sample-undertow</module> <module>spring-boot-sample-undertow</module>
<module>spring-boot-sample-undertow-ssl</module> <module>spring-boot-sample-undertow-ssl</module>
<module>spring-boot-sample-velocity</module>
<module>spring-boot-sample-war</module> <module>spring-boot-sample-war</module>
<module>spring-boot-sample-web-freemarker</module> <module>spring-boot-sample-web-freemarker</module>
<module>spring-boot-sample-web-groovy-templates</module> <module>spring-boot-sample-web-groovy-templates</module>
...@@ -107,7 +106,6 @@ ...@@ -107,7 +106,6 @@
<module>spring-boot-sample-web-static</module> <module>spring-boot-sample-web-static</module>
<module>spring-boot-sample-web-thymeleaf3</module> <module>spring-boot-sample-web-thymeleaf3</module>
<module>spring-boot-sample-web-ui</module> <module>spring-boot-sample-web-ui</module>
<module>spring-boot-sample-web-velocity</module>
<module>spring-boot-sample-websocket-jetty</module> <module>spring-boot-sample-websocket-jetty</module>
<module>spring-boot-sample-websocket-tomcat</module> <module>spring-boot-sample-websocket-tomcat</module>
<module>spring-boot-sample-websocket-undertow</module> <module>spring-boot-sample-websocket-undertow</module>
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-antlib</artifactId> <artifactId>spring-boot-antlib</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version> <version>2.0.0.BUILD-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</plugin> </plugin>
......
...@@ -10,7 +10,6 @@ abstraction is supported by many caching libraries, including: ...@@ -10,7 +10,6 @@ abstraction is supported by many caching libraries, including:
* `Couchbase` * `Couchbase`
* `Redis` * `Redis`
* `Caffeine` * `Caffeine`
* `Guava`
* Simple provider based on `ConcurrentHashMap` * Simple provider based on `ConcurrentHashMap`
* Generic provider based on `org.springframework.Cache` bean definition(s) * Generic provider based on `org.springframework.Cache` bean definition(s)
...@@ -99,11 +98,3 @@ a redis instance with the default settings is expected on your local box). ...@@ -99,11 +98,3 @@ a redis instance with the default settings is expected on your local box).
Simply add the `com.github.ben-manes.caffeine:caffeine` dependency to enable support Simply add the `com.github.ben-manes.caffeine:caffeine` dependency to enable support
for Caffeine. You can customize how caches are created in different ways, see for Caffeine. You can customize how caches are created in different ways, see
`application.properties` for an example and the documentation for more details. `application.properties` for an example and the documentation for more details.
=== Guava
Spring Boot does not provide any dependency management for _Guava_ so you'll have to add
the `com.google.guava:guava` dependency with a version. You can customize how caches are
created in different ways, see `application.properties` for an example and the
documentation for more details.
...@@ -96,13 +96,6 @@ ...@@ -96,13 +96,6 @@
<artifactId>caffeine</artifactId> <artifactId>caffeine</artifactId>
</dependency> </dependency>
--> -->
<!--
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -14,9 +14,3 @@ ...@@ -14,9 +14,3 @@
# Caffeine configuration # Caffeine configuration
# #
#spring.cache.caffeine.spec=maximumSize=200,expireAfterAccess=600s #spring.cache.caffeine.spec=maximumSize=200,expireAfterAccess=600s
#
# Guava configuration
#
#spring.cache.guava.spec=maximumSize=200,expireAfterAccess=600s
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-velocity</artifactId>
<name>Spring Boot Web Velocity Sample</name>
<description>Spring Boot Web Velocity Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2012-2014 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 sample.velocity;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.ui.velocity.VelocityEngineUtils;
@SpringBootApplication
@Deprecated
public class SampleVelocityApplication implements CommandLineRunner {
@Value("${application.message}")
private String message;
@Autowired
private VelocityEngine engine;
@Override
public void run(String... args) throws Exception {
Map<String, Object> model = new HashMap<String, Object>();
model.put("time", new Date());
model.put("message", this.message);
System.out.println(VelocityEngineUtils.mergeTemplateIntoString(this.engine,
"welcome.vm", "UTF-8", model));
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleVelocityApplication.class, args);
}
}
From application: $time
Message: $message
\ No newline at end of file
/*
* Copyright 2012-2016 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 sample.velocity;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Basic integration tests for Velocity application with no web layer.
*
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class SampleVelocityApplicationTests {
@ClassRule
public static OutputCapture output = new OutputCapture();
@Test
public void testVelocityTemplate() throws Exception {
String result = SampleVelocityApplicationTests.output.toString();
assertThat(result).contains("Hello, Andy");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-web-velocity</artifactId>
<name>Spring Boot Web Velocity Sample</name>
<description>Spring Boot Web Velocity Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2012-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 sample.web.velocity;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SampleWebVelocityApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebVelocityApplication.class, args);
}
}
/*
* Copyright 2012-2016 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 sample.web.velocity;
import java.util.Date;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class WelcomeController {
@Value("${application.message:Hello World}")
private String message = "Hello World";
@GetMapping("/")
public String welcome(Map<String, Object> model) {
model.put("time", new Date());
model.put("message", this.message);
return "welcome";
}
}
application.message: Hello, Andy
spring.velocity.dateToolAttribute: dateTool
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<body>
Something went wrong: ${status} ${error}
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<body>
<span>Time:</span>
<ul>
<li>From controller: $time</li>
<li>From velocity: $dateTool</li>
</ul>
<span>Message: $message</span>
</body>
</html>
/*
* Copyright 2012-2016 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 sample.web.velocity;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Basic integration tests for Velocity application.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class SampleWebVelocityApplicationTests {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void testVelocityTemplate() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("Hello, Andy");
}
@Test
public void testVelocityErrorTemplate() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> responseEntity = this.restTemplate
.exchange("/does-not-exist", HttpMethod.GET, requestEntity, String.class);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(responseEntity.getBody())
.contains("Something went wrong: 404 Not Found");
}
}
...@@ -67,7 +67,6 @@ ...@@ -67,7 +67,6 @@
<module>spring-boot-starter-tomcat</module> <module>spring-boot-starter-tomcat</module>
<module>spring-boot-starter-undertow</module> <module>spring-boot-starter-undertow</module>
<module>spring-boot-starter-validation</module> <module>spring-boot-starter-validation</module>
<module>spring-boot-starter-velocity</module>
<module>spring-boot-starter-web</module> <module>spring-boot-starter-web</module>
<module>spring-boot-starter-websocket</module> <module>spring-boot-starter-websocket</module>
<module>spring-boot-starter-web-services</module> <module>spring-boot-starter-web-services</module>
......
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starters</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-starter-velocity</artifactId>
<name>Spring Boot Velocity Starter</name>
<description>Starter for building MVC web applications using Velocity views.
Deprecated since 1.4</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
</dependencies>
</project>
...@@ -109,16 +109,6 @@ ...@@ -109,16 +109,6 @@
<artifactId>tomcat-embed-jasper</artifactId> <artifactId>tomcat-embed-jasper</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
......
...@@ -86,22 +86,6 @@ public class RelaxedPropertyResolver implements PropertyResolver { ...@@ -86,22 +86,6 @@ public class RelaxedPropertyResolver implements PropertyResolver {
return defaultValue; return defaultValue;
} }
@Override
@Deprecated
public <T> Class<T> getPropertyAsClass(String key, Class<T> targetType) {
RelaxedNames prefixes = new RelaxedNames(this.prefix);
RelaxedNames keys = new RelaxedNames(key);
for (String prefix : prefixes) {
for (String relaxedKey : keys) {
if (this.resolver.containsProperty(prefix + relaxedKey)) {
return this.resolver.getPropertyAsClass(prefix + relaxedKey,
targetType);
}
}
}
return null;
}
@Override @Override
public boolean containsProperty(String key) { public boolean containsProperty(String key) {
RelaxedNames prefixes = new RelaxedNames(this.prefix); RelaxedNames prefixes = new RelaxedNames(this.prefix);
......
...@@ -362,7 +362,6 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext ...@@ -362,7 +362,6 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
Set<String> scopes = new LinkedHashSet<String>(); Set<String> scopes = new LinkedHashSet<String>();
scopes.add(WebApplicationContext.SCOPE_REQUEST); scopes.add(WebApplicationContext.SCOPE_REQUEST);
scopes.add(WebApplicationContext.SCOPE_SESSION); scopes.add(WebApplicationContext.SCOPE_SESSION);
scopes.add(WebApplicationContext.SCOPE_GLOBAL_SESSION);
SCOPES = Collections.unmodifiableSet(scopes); SCOPES = Collections.unmodifiableSet(scopes);
} }
......
/*
* Copyright 2012-2016 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 org.springframework.boot.web.servlet.view.velocity;
import java.io.InputStream;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.servlet.view.velocity.VelocityToolboxView;
/**
* Extended version of {@link VelocityToolboxView} that can load toolbox locations from
* the classpath as well as the servlet context. This is useful when running in an
* embedded web server.
*
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.2.5
*/
@SuppressWarnings("deprecation")
public class EmbeddedVelocityToolboxView extends VelocityToolboxView {
@Override
protected Context createVelocityContext(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
org.apache.velocity.tools.view.context.ChainedContext context = new org.apache.velocity.tools.view.context.ChainedContext(
new VelocityContext(model), getVelocityEngine(), request, response,
getServletContext());
if (getToolboxConfigLocation() != null) {
setContextToolbox(context);
}
return context;
}
@SuppressWarnings("unchecked")
private void setContextToolbox(
org.apache.velocity.tools.view.context.ChainedContext context) {
org.apache.velocity.tools.view.ToolboxManager toolboxManager = org.apache.velocity.tools.view.servlet.ServletToolboxManager
.getInstance(getToolboxConfigFileAwareServletContext(),
getToolboxConfigLocation());
Map<String, Object> toolboxContext = toolboxManager.getToolbox(context);
context.setToolbox(toolboxContext);
}
private ServletContext getToolboxConfigFileAwareServletContext() {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(getServletContext());
factory.addAdvice(new GetResourceMethodInterceptor(getToolboxConfigLocation()));
return (ServletContext) factory.getProxy(getClass().getClassLoader());
}
/**
* {@link MethodInterceptor} to allow the calls to getResourceAsStream() to resolve
* the toolboxFile from the classpath.
*/
private static class GetResourceMethodInterceptor implements MethodInterceptor {
private final String toolboxFile;
GetResourceMethodInterceptor(String toolboxFile) {
if (toolboxFile != null && !toolboxFile.startsWith("/")) {
toolboxFile = "/" + toolboxFile;
}
this.toolboxFile = toolboxFile;
}
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
if (invocation.getMethod().getName().equals("getResourceAsStream")
&& invocation.getArguments()[0].equals(this.toolboxFile)) {
InputStream inputStream = (InputStream) invocation.proceed();
if (inputStream == null) {
try {
inputStream = new ClassPathResource(this.toolboxFile,
Thread.currentThread().getContextClassLoader())
.getInputStream();
}
catch (Exception ex) {
// Ignore
}
}
return inputStream;
}
return invocation.proceed();
}
}
}
/*
* Copyright 2012-2016 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 org.springframework.boot.web.servlet.view.velocity;
import org.springframework.web.servlet.view.velocity.VelocityView;
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
/**
* Extended version of {@link VelocityViewResolver} that uses
* {@link EmbeddedVelocityToolboxView} when the {@link #setToolboxConfigLocation(String)
* toolboxConfigLocation} is set.
*
* @author Phillip Webb
* @since 1.2.5
* @deprecated as of 1.4 following the deprecation of Velocity support in Spring Framework
* 4.3
*/
@Deprecated
public class EmbeddedVelocityViewResolver extends VelocityViewResolver {
private String toolboxConfigLocation;
@Override
protected void initApplicationContext() {
if (this.toolboxConfigLocation != null) {
if (VelocityView.class.equals(getViewClass())) {
this.logger.info("Using EmbeddedVelocityToolboxView instead of "
+ "default VelocityView due to specified toolboxConfigLocation");
setViewClass(EmbeddedVelocityToolboxView.class);
}
}
super.initApplicationContext();
}
@Override
public void setToolboxConfigLocation(String toolboxConfigLocation) {
super.setToolboxConfigLocation(toolboxConfigLocation);
this.toolboxConfigLocation = toolboxConfigLocation;
}
}
/*
* Copyright 2012-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.
*/
/**
* Velocity support classes.
*/
package org.springframework.boot.web.servlet.view.velocity;
...@@ -118,14 +118,6 @@ public class RelaxedPropertyResolverTests { ...@@ -118,14 +118,6 @@ public class RelaxedPropertyResolverTests {
.isEqualTo(345); .isEqualTo(345);
} }
@Test
@Deprecated
public void getPropertyAsClass() throws Exception {
assertThat(this.resolver.getPropertyAsClass("my-class", String.class))
.isEqualTo(String.class);
assertThat(this.resolver.getPropertyAsClass("my-missing", String.class)).isNull();
}
@Test @Test
public void containsProperty() throws Exception { public void containsProperty() throws Exception {
assertThat(this.resolver.containsProperty("my-string")).isTrue(); assertThat(this.resolver.containsProperty("my-string")).isTrue();
......
...@@ -31,8 +31,6 @@ import javax.servlet.ServletException; ...@@ -31,8 +31,6 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import org.apache.struts.mock.MockHttpServletRequest;
import org.apache.struts.mock.MockHttpServletResponse;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -63,6 +61,8 @@ import org.springframework.core.annotation.Order; ...@@ -63,6 +61,8 @@ import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockFilterConfig; import org.springframework.mock.web.MockFilterConfig;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.ServletContextAware;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.SessionScope; import org.springframework.web.context.request.SessionScope;
...@@ -471,15 +471,12 @@ public class EmbeddedWebApplicationContextTests { ...@@ -471,15 +471,12 @@ public class EmbeddedWebApplicationContextTests {
ConfigurableListableBeanFactory factory = this.context.getBeanFactory(); ConfigurableListableBeanFactory factory = this.context.getBeanFactory();
factory.registerScope(WebApplicationContext.SCOPE_REQUEST, scope); factory.registerScope(WebApplicationContext.SCOPE_REQUEST, scope);
factory.registerScope(WebApplicationContext.SCOPE_SESSION, scope); factory.registerScope(WebApplicationContext.SCOPE_SESSION, scope);
factory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, scope);
addEmbeddedServletContainerFactoryBean(); addEmbeddedServletContainerFactoryBean();
this.context.refresh(); this.context.refresh();
assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_REQUEST)) assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_REQUEST))
.isSameAs(scope); .isSameAs(scope);
assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_SESSION)) assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_SESSION))
.isSameAs(scope); .isSameAs(scope);
assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_GLOBAL_SESSION))
.isSameAs(scope);
} }
private void addEmbeddedServletContainerFactoryBean() { private void addEmbeddedServletContainerFactoryBean() {
......
/*
* Copyright 2012-2016 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 org.springframework.boot.web.servlet.view.velocity;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.mock.MockHttpServletRequest;
import org.apache.struts.mock.MockHttpServletResponse;
import org.apache.struts.mock.MockServletContext;
import org.apache.velocity.tools.ToolContext;
import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link EmbeddedVelocityToolboxView}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
public class EmbeddedVelocityToolboxViewTests {
private static final String PATH = EmbeddedVelocityToolboxViewTests.class.getPackage()
.getName().replace(".", "/");
@Test
public void loadsContextFromClassPath() throws Exception {
ToolContext context = getToolContext(PATH + "/toolbox.xml");
assertThat(context.getToolbox().keySet()).contains("math");
}
@Test
public void loadsWithoutConfig() throws Exception {
ToolContext context = getToolContext(null);
assertThat(context).isNotNull();
}
private ToolContext getToolContext(String toolboxConfigLocation) throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(Config.class);
context.refresh();
EmbeddedVelocityToolboxView view = context
.getBean(EmbeddedVelocityToolboxView.class);
view.setToolboxConfigLocation(toolboxConfigLocation);
Map<String, Object> model = new LinkedHashMap<String, Object>();
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
ToolContext toolContext = (ToolContext) view.createVelocityContext(model, request,
response);
context.close();
return toolContext;
}
@Configuration
static class Config {
@Bean
public EmbeddedVelocityToolboxView view() {
EmbeddedVelocityToolboxView view = new EmbeddedVelocityToolboxView();
view.setUrl("http://example.com");
return view;
}
@Bean
public VelocityConfigurer velocityConfigurer() {
return new VelocityConfigurer();
}
}
}
/*
* Copyright 2012-2016 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 org.springframework.boot.web.servlet.view.velocity;
import org.apache.struts.mock.MockServletContext;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
import org.springframework.web.servlet.view.velocity.VelocityView;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link EmbeddedVelocityViewResolver}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
public class EmbeddedVelocityViewResolverTests {
@Test
public void standardViewWithoutToolboxConfig() throws Exception {
ApplicationContext context = loadContext(WithoutToolboxConfig.class);
EmbeddedVelocityViewResolver resolver = context
.getBean(EmbeddedVelocityViewResolver.class);
Object viewClass = ReflectionTestUtils.getField(resolver, "viewClass");
assertThat(viewClass).isEqualTo(VelocityView.class);
}
@Test
public void embeddedViewWithToolboxConfig() throws Exception {
ApplicationContext context = loadContext(WithToolboxConfig.class);
EmbeddedVelocityViewResolver resolver = context
.getBean(EmbeddedVelocityViewResolver.class);
Object viewClass = ReflectionTestUtils.getField(resolver, "viewClass");
assertThat(viewClass).isEqualTo(EmbeddedVelocityToolboxView.class);
}
private ApplicationContext loadContext(Class<?> config) {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(config);
context.refresh();
return context;
}
@Configuration
static class WithoutToolboxConfig {
@Bean
public EmbeddedVelocityViewResolver resolver() {
return new EmbeddedVelocityViewResolver();
}
@Bean
public VelocityConfigurer velocityConfigurer() {
return new VelocityConfigurer();
}
}
@Configuration
static class WithToolboxConfig {
@Bean
public EmbeddedVelocityViewResolver resolver() {
EmbeddedVelocityViewResolver resolver = new EmbeddedVelocityViewResolver();
resolver.setToolboxConfigLocation("/toolbox.xml");
return resolver;
}
@Bean
public VelocityConfigurer velocityConfigurer() {
return new VelocityConfigurer();
}
}
}
<?xml version="1.0"?>
<toolbox>
<tool>
<key>math</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>
</toolbox>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment