Announcement Announcement Module
Collapse
No announcement yet.
velocity .vm resource not found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • velocity .vm resource not found

    Hi,
    I am working on a web project where i need to send scheduled mails.
    I am using velocity 1.5 for mail formats.

    The velocity configuration i am doing at applicationcontext is,

    <bean id="velocityConfig" class="org.springframework.web.servlet.view.veloci ty.VelocityConfigurer">
    <property name="resourceLoaderPath">
    <value>"/WEB-INF/velocity"</value>
    </property>
    </bean>

    .vm files are placed at /WEB-INF/velocity folder.

    In code i am trying
    System.out.println("1 :"+Velocity.resourceExists("Hello.vm"));
    System.out.println("2 :"+Velocity.resourceExists("/WEB-INF/velocity/Hello.vm"));
    System.out.println("3 :"+Velocity.resourceExists("/velocity/Hello.vm"));
    System.out.println("4 :"+Velocity.resourceExists("./Hello.vm"));
    But everything is returning 'FALSE'.

    Even i tried to configure VelocityEngine in applicationcontext like,

    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEng ineFactoryBean">
    <property name="velocityProperties">
    <value>
    resource.loader=class
    class.resource.loader.class=org.apache.velocity.ru ntime.resource.loader.ClasspathResourceLoader
    </value>
    </property>
    </bean>
    and then tried code,

    @Qualifier("velocityEngine")
    private VelocityEngine ve=null;


    System.out.println("1 :"+ve.resourceExists("Hello.vm"));
    System.out.println("2 :"+ve.resourceExists("/WEB-INF/velocity/Hello.vm"));
    System.out.println("3 :"+ve.resourceExists("/velocity/Hello.vm"));
    System.out.println("4 :"+ve.resourceExists("./Hello.vm"));
    But even this returns 'FALSE'.

    I am not getting exactly what i am missing here. Has any one faced this issue earlier and able to resolve?


    Thanks,
    Samir

  • #2
    Hi

    First - you have:
    Code:
    <bean id="velocityConfig" class="org.springframework.web.servlet.view.veloci ty.VelocityConfigurer">
    <property name="resourceLoaderPath">
    <value>"/WEB-INF/velocity"</value>
    </property>
    </bean>
    Get rid of those quotes.

    Second - "/WEB-INF/velocity" is not on your classpath (at least according to Java Servlets specification). So using ClasspathResourceLoader won't work. Either move your templates to /WEB-INF/classes/velocity and Velocity.resourceExists("/velocity/Hello.vm") should work or use other ResourceLoader (e.g. org.springframework.ui.velocity.SpringResourceLoad er).

    regards
    Grzegorz Grzybek

    Comment

    Working...
    X