복붙노트

[SPRING] VelocityEngineUtils은 Spring 3.2에서 삭제되었으므로 사용할 다른 것들은 무엇입니까?

SPRING

VelocityEngineUtils은 Spring 3.2에서 삭제되었으므로 사용할 다른 것들은 무엇입니까?

오늘 전체 Spring 웹 애플리케이션을 Spring 3.1.1에서 Spring 3.2로 업그레이드했다.

내 기존 앱의 대부분은 Spring 3.2에서

org.springframework.ui.velocity.VelocityEngineUtils

클래스는 spring-context-3.2.0.RELEASE.jar에서 완전히 제거 된 것처럼 보입니다.

이 URL과 같이 이전 가이드를 찾았습니다.

org.springframework.ui.velocity.VelocityEngineUtils 클래스는 이제 막 사용되지 않았지만 실제로 완전히 제거되었습니다.

아마 내가 실수 한 것일 뿐이므로 VelocityEngineUtils 클래스가 여전히 어딘가에 존재하는지, 아니면 사용하지 않는지, 내가 사용할 수있는 대체 클래스는 무엇인지 알고 싶습니다.

편집 : 전체 속도 패키지가 봄 3.2에서 지금 제거 된 것 같습니다 org.springframework.ui.velocity.VelocityEngineFactoryBean이 존재하지 않습니다. 봄이 Velocity에서 멀어지고 있습니까?

해결법

  1. ==============================

    1.저는 VelocityEngineUtils가 스프링 컨텍스트 항아리에 있다고 생각하지 않습니다. 적어도 GitHub에 따르면 Spring 3.1.x 릴리즈 이후로는 아닙니다.

    저는 VelocityEngineUtils가 스프링 컨텍스트 항아리에 있다고 생각하지 않습니다. 적어도 GitHub에 따르면 Spring 3.1.x 릴리즈 이후로는 아닙니다.

    어쨌든 spring-context-support-3.2.0.RELEASE.jar에서 찾을 수 있습니다.

  2. ==============================

    2.나는 완전한 대답을 덧붙이고 싶었다.

    나는 완전한 대답을 덧붙이고 싶었다.

    먼저, 종속성을 추가합니다.

        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.6.4</version>
        </dependency>
    

    그런 다음 이와 같은 맞춤 VelocityEngineFactory가 있다면;

    @Bean
    public VelocityEngineFactory velocityEngine(){
        VelocityEngineFactoryBean bean = new VelocityEngineFactoryBean();
        Properties properties = new Properties();
        properties.setProperty("input.encoding", "UTF-8");
        properties.setProperty("output.encoding", "UTF-8");
        properties.setProperty("resource.loader", "class");
        properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        bean.setVelocityProperties(properties);
        return bean;
    }
    

    다음과 같이 (@Configuration 클래스에) bean 정의로 바꿔야한다.

    @Bean
    public VelocityEngine velocityEngine() throws Exception {
        Properties properties = new Properties();
        properties.setProperty("input.encoding", "UTF-8");
        properties.setProperty("output.encoding", "UTF-8");
        properties.setProperty("resource.loader", "class");
        properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        VelocityEngine velocityEngine = new VelocityEngine(properties);
        return velocityEngine;
    }
    

    마지막으로 다음과 같이 사용하십시오.

    @Autowired
    private VelocityEngine velocityEngine;
    
    public String prepareRegistrationEmailText(User user) {
        VelocityContext context = new VelocityContext();
        context.put("username", user.getUsername());
        context.put("email", user.getEmail());
        StringWriter stringWriter = new StringWriter();
        velocityEngine.mergeTemplate("registration.vm", "UTF-8", context, stringWriter);
        String text = stringWriter.toString();
        return text;
    }
    

    행운을 빕니다.

  3. ==============================

    3.Spring에서의 VelocityEngineUtils의 비추천에 관해서, Spring 문서는 무엇을 대신 사용해야하는지에 대해 명확하지 않습니다.

    Spring에서의 VelocityEngineUtils의 비추천에 관해서, Spring 문서는 무엇을 대신 사용해야하는지에 대해 명확하지 않습니다.

    그것은 단지 말한다 :

    그리고 더 혼란스럽게 만들기 위해, 링크 자체를 참조하십시오.

    기본적으로 Velocity 자체를 사용하는 것입니다.

    어떻게 그렇게하는지에 대한 설명이 있습니다.

     // instead of a model map, you use a VelocityContext
    
     VelocityContext velocityContext = new VelocityContext();
     velocityContext.put("key1", value1);
     velocityContext.put("key2", value2);
    
     // the velocityEngine you wired into Spring has a mergeTemplate function
     // you can use to do the same thing as VelocityEngineUtils.mergeTemplate
     // with the exception that it uses a writer instead of returning a String      
    
     StringWriter stringWriter = new StringWriter();
     velocityEngine.mergeTemplate("templateName.vm", "UTF-8", velocityContext, stringWriter);
    
     // this is assuming you're sending HTML email using MimeMessageHelper
    
     message.setText(stringWriter.toString(), true);
    
  4. from https://stackoverflow.com/questions/14314143/velocityengineutils-has-been-removed-in-spring-3-2-so-what-else-to-use by cc-by-sa and MIT license