Skip to content

Commit a2a9c47

Browse files
committed
Deprecate Velocity support
Issue: SPR-13235
1 parent 8ce5e88 commit a2a9c47

File tree

13 files changed

+34
-51
lines changed

13 files changed

+34
-51
lines changed

spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java

+2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
* @see VelocityEngineFactoryBean
7070
* @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
7171
* @see org.apache.velocity.app.VelocityEngine
72+
* @deprecated as of Spring 4.3, in favor of FreeMarker
7273
*/
74+
@Deprecated
7375
public class VelocityEngineFactory {
7476

7577
protected final Log logger = LogFactory.getLog(getClass());

spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactoryBean.java

+2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
* @see #setVelocityProperties
4747
* @see #setResourceLoaderPath
4848
* @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
49+
* @deprecated as of Spring 4.3, in favor of FreeMarker
4950
*/
51+
@Deprecated
5052
public class VelocityEngineFactoryBean extends VelocityEngineFactory
5153
implements FactoryBean<VelocityEngine>, InitializingBean, ResourceLoaderAware {
5254

spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
*
3131
* @author Juergen Hoeller
3232
* @since 22.01.2004
33+
* @deprecated as of Spring 4.3, in favor of FreeMarker
3334
*/
35+
@Deprecated
3436
public abstract class VelocityEngineUtils {
3537

3638
/**

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver;
4040
import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver;
4141
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
42-
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
4342

4443
/**
4544
* Parse the {@code view-resolvers} MVC namespace element and register
@@ -69,6 +68,7 @@ public class ViewResolversBeanDefinitionParser implements BeanDefinitionParser {
6968
public static final String VIEW_RESOLVER_BEAN_NAME = "mvcViewResolver";
7069

7170

71+
@SuppressWarnings("deprecation")
7272
public BeanDefinition parse(Element element, ParserContext context) {
7373
Object source = context.extractSource(element);
7474
context.pushContainingComponent(new CompositeComponentDefinition(element.getTagName(), source));
@@ -100,7 +100,7 @@ else if ("freemarker".equals(name)) {
100100
addUrlBasedViewResolverProperties(resolverElement, resolverBeanDef);
101101
}
102102
else if ("velocity".equals(name)) {
103-
resolverBeanDef = new RootBeanDefinition(VelocityViewResolver.class);
103+
resolverBeanDef = new RootBeanDefinition(org.springframework.web.servlet.view.velocity.VelocityViewResolver.class);
104104
resolverBeanDef.getPropertyValues().add("suffix", ".vm");
105105
addUrlBasedViewResolverProperties(resolverElement, resolverBeanDef);
106106
}

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java

+11-19
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver;
4242
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
4343
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
44-
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
45-
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
4644

4745
/**
4846
* Assist with the configuration of a chain of
@@ -86,10 +84,8 @@ public boolean hasRegistrations() {
8684
* Enable use of a {@link ContentNegotiatingViewResolver} to front all other
8785
* configured view resolvers and select among all selected Views based on
8886
* media types requested by the client (e.g. in the Accept header).
89-
*
9087
* <p>If invoked multiple times the provided default views will be added to
9188
* any other default views that may have been configured already.
92-
*
9389
* @see ContentNegotiatingViewResolver#setDefaultViews
9490
*/
9591
public void enableContentNegotiation(View... defaultViews) {
@@ -100,7 +96,6 @@ public void enableContentNegotiation(View... defaultViews) {
10096
* Enable use of a {@link ContentNegotiatingViewResolver} to front all other
10197
* configured view resolvers and select among all selected Views based on
10298
* media types requested by the client (e.g. in the Accept header).
103-
*
10499
* <p>If invoked multiple times the provided default views will be added to
105100
* any other default views that may have been configured already.
106101
*
@@ -112,9 +107,8 @@ public void enableContentNegotiation(boolean useNotAcceptableStatus, View... def
112107
}
113108

114109
private void initContentNegotiatingViewResolver(View[] defaultViews) {
115-
116110
// ContentNegotiatingResolver in the registry: elevate its precedence!
117-
this.order = (this.order == null ? Ordered.HIGHEST_PRECEDENCE : this.order);
111+
this.order = (this.order != null ? this.order : Ordered.HIGHEST_PRECEDENCE);
118112

119113
if (this.contentNegotiatingResolver != null) {
120114
if (!ObjectUtils.isEmpty(defaultViews)) {
@@ -136,7 +130,6 @@ private void initContentNegotiatingViewResolver(View[] defaultViews) {
136130
/**
137131
* Register JSP view resolver using a default view name prefix of "/WEB-INF/"
138132
* and a default suffix of ".jsp".
139-
*
140133
* <p>When this method is invoked more than once, each call will register a
141134
* new ViewResolver instance. Note that since it's not easy to determine
142135
* if a JSP exists without forwarding to it, using multiple JSP-based view
@@ -149,7 +142,6 @@ public UrlBasedViewResolverRegistration jsp() {
149142

150143
/**
151144
* Register JSP view resolver with the specified prefix and suffix.
152-
*
153145
* <p>When this method is invoked more than once, each call will register a
154146
* new ViewResolver instance. Note that since it's not easy to determine
155147
* if a JSP exists without forwarding to it, using multiple JSP-based view
@@ -166,7 +158,6 @@ public UrlBasedViewResolverRegistration jsp(String prefix, String suffix) {
166158

167159
/**
168160
* Register Tiles 3.x view resolver.
169-
*
170161
* <p><strong>Note</strong> that you must also configure Tiles by adding a
171162
* {@link org.springframework.web.servlet.view.tiles3.TilesConfigurer} bean.
172163
*/
@@ -184,7 +175,6 @@ public UrlBasedViewResolverRegistration tiles() {
184175
/**
185176
* Register a FreeMarker view resolver with an empty default view name
186177
* prefix and a default suffix of ".ftl".
187-
*
188178
* <p><strong>Note</strong> that you must also configure FreeMarker by adding a
189179
* {@link org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer} bean.
190180
*/
@@ -203,12 +193,13 @@ public UrlBasedViewResolverRegistration freeMarker() {
203193
/**
204194
* Register Velocity view resolver with an empty default view name
205195
* prefix and a default suffix of ".vm".
206-
*
207196
* <p><strong>Note</strong> that you must also configure Velocity by adding a
208197
* {@link org.springframework.web.servlet.view.velocity.VelocityConfigurer} bean.
198+
* @deprecated as of Spring 4.3, in favor of FreeMarker
209199
*/
200+
@Deprecated
210201
public UrlBasedViewResolverRegistration velocity() {
211-
if (this.applicationContext != null && !hasBeanOfType(VelocityConfigurer.class)) {
202+
if (this.applicationContext != null && !hasBeanOfType(org.springframework.web.servlet.view.velocity.VelocityConfigurer.class)) {
212203
throw new BeanInitializationException("In addition to a Velocity view resolver " +
213204
"there must also be a single VelocityConfig bean in this web application context " +
214205
"(or its parent): VelocityConfigurer is the usual implementation. " +
@@ -313,38 +304,39 @@ protected List<ViewResolver> getViewResolvers() {
313304

314305
private static class TilesRegistration extends UrlBasedViewResolverRegistration {
315306

316-
private TilesRegistration() {
307+
public TilesRegistration() {
317308
super(new TilesViewResolver());
318309
}
319310
}
320311

321312
private static class VelocityRegistration extends UrlBasedViewResolverRegistration {
322313

323-
private VelocityRegistration() {
324-
super(new VelocityViewResolver());
314+
@SuppressWarnings("deprecation")
315+
public VelocityRegistration() {
316+
super(new org.springframework.web.servlet.view.velocity.VelocityViewResolver());
325317
getViewResolver().setSuffix(".vm");
326318
}
327319
}
328320

329321
private static class FreeMarkerRegistration extends UrlBasedViewResolverRegistration {
330322

331-
private FreeMarkerRegistration() {
323+
public FreeMarkerRegistration() {
332324
super(new FreeMarkerViewResolver());
333325
getViewResolver().setSuffix(".ftl");
334326
}
335327
}
336328

337329
private static class GroovyMarkupRegistration extends UrlBasedViewResolverRegistration {
338330

339-
private GroovyMarkupRegistration() {
331+
public GroovyMarkupRegistration() {
340332
super(new GroovyMarkupViewResolver());
341333
getViewResolver().setSuffix(".tpl");
342334
}
343335
}
344336

345337
private static class ScriptRegistration extends UrlBasedViewResolverRegistration {
346338

347-
private ScriptRegistration() {
339+
public ScriptRegistration() {
348340
super(new ScriptTemplateViewResolver());
349341
getViewResolver();
350342
}

spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfig.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
* @author Rod Johnson
2727
* @see VelocityConfigurer
2828
* @see VelocityView
29+
* @deprecated as of Spring 4.3, in favor of FreeMarker
2930
*/
31+
@Deprecated
3032
public interface VelocityConfig {
3133

3234
/**

spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfigurer.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import org.springframework.beans.factory.InitializingBean;
2727
import org.springframework.context.ResourceLoaderAware;
28-
import org.springframework.ui.velocity.VelocityEngineFactory;
2928
import org.springframework.web.context.ServletContextAware;
3029

3130
/**
@@ -69,8 +68,10 @@
6968
* @see #setResourceLoaderPath
7069
* @see #setVelocityEngine
7170
* @see VelocityView
71+
* @deprecated as of Spring 4.3, in favor of FreeMarker
7272
*/
73-
public class VelocityConfigurer extends VelocityEngineFactory
73+
@Deprecated
74+
public class VelocityConfigurer extends org.springframework.ui.velocity.VelocityEngineFactory
7475
implements VelocityConfig, InitializingBean, ResourceLoaderAware, ServletContextAware {
7576

7677
/** the name of the resource loader for Spring's bind macros */

spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutView.java

+2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
* @see #setLayoutUrl
5151
* @see #setLayoutKey
5252
* @see #setScreenContentKey
53+
* @deprecated as of Spring 4.3, in favor of FreeMarker
5354
*/
55+
@Deprecated
5456
public class VelocityLayoutView extends VelocityToolboxView {
5557

5658
/**

spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutViewResolver.java

+2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
* @see #setLayoutUrl
3232
* @see #setLayoutKey
3333
* @see #setScreenContentKey
34+
* @deprecated as of Spring 4.3, in favor of FreeMarker
3435
*/
36+
@Deprecated
3537
public class VelocityLayoutViewResolver extends VelocityViewResolver {
3638

3739
private String layoutUrl;

spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityToolboxView.java

+2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
* @see #initTool
6363
* @see org.apache.velocity.tools.view.context.ViewContext
6464
* @see org.apache.velocity.tools.view.context.ChainedContext
65+
* @deprecated as of Spring 4.3, in favor of FreeMarker
6566
*/
67+
@Deprecated
6668
public class VelocityToolboxView extends VelocityView {
6769

6870
private String toolboxConfigLocation;

spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityView.java

+2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
* @see #setVelocityEngine
8484
* @see VelocityConfig
8585
* @see VelocityConfigurer
86+
* @deprecated as of Spring 4.3, in favor of FreeMarker
8687
*/
88+
@Deprecated
8789
public class VelocityView extends AbstractTemplateView {
8890

8991
private Map<String, Class<?>> toolAttributes;

spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityViewResolver.java

+2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
* @see #setDateToolAttribute
4141
* @see #setNumberToolAttribute
4242
* @see VelocityView
43+
* @deprecated as of Spring 4.3, in favor of FreeMarker
4344
*/
45+
@Deprecated
4446
public class VelocityViewResolver extends AbstractTemplateViewResolver {
4547

4648
private String dateToolAttribute;

spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.3.xsd

-28
Original file line numberDiff line numberDiff line change
@@ -1022,16 +1022,6 @@
10221022
]]></xsd:documentation>
10231023
</xsd:annotation>
10241024
</xsd:element>
1025-
<xsd:element name="velocity" type="urlViewResolverType">
1026-
<xsd:annotation>
1027-
<xsd:documentation><![CDATA[
1028-
Register a VelocityViewResolver.
1029-
By default, ".vm" is configured as a view name suffix.
1030-
To configure Velocity you must also add a top-level <mvc:velocity-configurer> element
1031-
or declare a VelocityConfigurer bean.
1032-
]]></xsd:documentation>
1033-
</xsd:annotation>
1034-
</xsd:element>
10351025
<xsd:element name="groovy" type="urlViewResolverType">
10361026
<xsd:annotation>
10371027
<xsd:documentation><![CDATA[
@@ -1170,24 +1160,6 @@
11701160
</xsd:complexType>
11711161
</xsd:element>
11721162

1173-
<xsd:element name="velocity-configurer">
1174-
<xsd:annotation>
1175-
<xsd:documentation><![CDATA[
1176-
Configure Velocity for view resolution by registering a VelocityConfigurer bean.
1177-
This is a shortcut alternative to declaring a VelocityConfigurer bean directly.
1178-
]]></xsd:documentation>
1179-
</xsd:annotation>
1180-
<xsd:complexType>
1181-
<xsd:attribute name="resource-loader-path" type="xsd:string" use="required">
1182-
<xsd:annotation>
1183-
<xsd:documentation><![CDATA[
1184-
The Velocity resource loader path via a Spring resource location.
1185-
]]></xsd:documentation>
1186-
</xsd:annotation>
1187-
</xsd:attribute>
1188-
</xsd:complexType>
1189-
</xsd:element>
1190-
11911163
<xsd:element name="groovy-configurer">
11921164
<xsd:annotation>
11931165
<xsd:documentation><![CDATA[

0 commit comments

Comments
 (0)