001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.ui.velocity; 018 019import java.io.IOException; 020 021import org.apache.velocity.app.VelocityEngine; 022import org.apache.velocity.exception.VelocityException; 023 024import org.springframework.beans.factory.FactoryBean; 025import org.springframework.beans.factory.InitializingBean; 026import org.springframework.context.ResourceLoaderAware; 027 028/** 029 * Factory bean that configures a VelocityEngine and provides it as bean 030 * reference. This bean is intended for any kind of usage of Velocity in 031 * application code, e.g. for generating email content. For web views, 032 * VelocityConfigurer is used to set up a VelocityEngine for views. 033 * 034 * <p>The simplest way to use this class is to specify a "resourceLoaderPath"; 035 * you do not need any further configuration then. For example, in a web 036 * application context: 037 * 038 * <pre class="code"> <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> 039 * <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/> 040 * </bean></pre> 041 * 042 * See the base class VelocityEngineFactory for configuration details. 043 * 044 * @author Juergen Hoeller 045 * @see #setConfigLocation 046 * @see #setVelocityProperties 047 * @see #setResourceLoaderPath 048 * @see org.springframework.web.servlet.view.velocity.VelocityConfigurer 049 * @deprecated as of Spring 4.3, in favor of FreeMarker 050 */ 051@Deprecated 052public class VelocityEngineFactoryBean extends VelocityEngineFactory 053 implements FactoryBean<VelocityEngine>, InitializingBean, ResourceLoaderAware { 054 055 private VelocityEngine velocityEngine; 056 057 058 @Override 059 public void afterPropertiesSet() throws IOException, VelocityException { 060 this.velocityEngine = createVelocityEngine(); 061 } 062 063 064 @Override 065 public VelocityEngine getObject() { 066 return this.velocityEngine; 067 } 068 069 @Override 070 public Class<? extends VelocityEngine> getObjectType() { 071 return VelocityEngine.class; 072 } 073 074 @Override 075 public boolean isSingleton() { 076 return true; 077 } 078 079}