Wie bekommen VelocityEngine mit Velocity-Tools im Frühling 3

Wie bekommen VelocityEngine mit Velocity-Tools, die im Frühjahr 3?
Ich brauche eine Methode im controller zu verarbeiten, ein Velocity-template, jedoch müssen Velocity-Tools, die verfügbar sind, zum initialisieren der Frühling 3.
Jetzt mache ich es so.

Frühjahr Config:

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>        
        <property name="velocityProperties">
            <props>
                <prop key="input.encoding">UTF-8</prop>
                <prop key="output.encoding">UTF-8</prop>                
            </props>
        </property>                 
    </bean>

 <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="cache" value="false"/>
        <property name="prefix" value=""/>
        <property name="suffix" value=".html"/>        
        <property name="contentType" value="text/html; charset=UTF-8"/>     
        <property name="toolboxConfigLocation" value="/WEB-INF/velocity/config/toolbox.xml"/>
        <property name="viewClass" value="my.tools.VelocityToolsView"/> 
    </bean>

In der controller-Klasse:

@Autowired
private VelocityConfigurer configurer;

private VelocityEngine velocityEngine;


private ToolContext toolContext;

@PostConstruct
public void init() {                    

        velocityEngine = configurer.getVelocityEngine();

        ToolManager toolManager = new ToolManager();
        toolManager.configure("fuulPath/WEB-INF/velocity/config/toolbox.xml");
        toolContext = toolManager.createContext();



}

Methode:

    VelocityContext velocityContext = new VelocityContext(map, toolContext);                
    StringWriter writer = new StringWriter();        
    velocityEngine.mergeTemplate("myTeplate.html", "UTF-8", velocityContext, writer);        
    String templateString = writer.toString();   

InformationsquelleAutor rdm | 2013-01-09

Schreibe einen Kommentar