`
davidgrubby
  • 浏览: 23353 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论
  • davidgrubby: 啥玩意啊,没意义的就删掉啊,浪费人家的精力
    Test

Velocity, Can't find resource

阅读更多
Velocity 邮件模板在Spring 中发邮件报unable to find resource 'WEB-INF/test.vm' in any resource loader导常。配置如下:

    <bean id="templateMail" class="com.chenlb.mail.VelocityTemplateMessage">
        <property name="javaMailSender" ref="mailSender"></property>
        <property name="from" value="${mail.from}"></property>
        <property name="encoding" value="UTF-8"></property>
        <property name="templateLocation" value="WEB-INF/test.vm"></property>
        <property name="velocityEngine">
            <bean class="org.springframework.ui.velocity.VelocityEngineFactoryBean"></bean>
        </property>
        <property name="title" value="www.blogjava.net/chenlb"></property>
    </bean>

邮件内容生成如下:
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateLocation, encoding, model);

但导常,说不可用的资源。

说明:VelocityEngineUtils.mergeTemplateIntoString()里的templateLocation的文件,不会像Spring一样找。然后就看Spring 的 VelocityEnginFactory API和试,最后发现<bean class="org.springframework.ui.velocity.VelocityEngineFactoryBean"></bean>
单独定义,并配置resourceLoaderPath属性即可搞定。

配置后的:
    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
        <property name="resourceLoaderPath" value="WEB-INF/"></property>
    </bean>
   
    <bean id="templateMail" class="com.chenlb.mail.VelocityTemplateMessage">
        <property name="javaMailSender" ref="mailSender"></property>
        <property name="from" value="${mail.from}"></property>
        <property name="encoding" value="UTF-8"></property>
        <property name="templateLocation" value="test.vm"></property>
        <property name="velocityEngine" ref="velocityEngine"></property>
        <property name="title" value="wwww.blogjava.net/chenlb"></property>
    </bean>

resourceLoaderPath是由Spring设置过的,跟平常的(Spring)文件资源一样方式引用,Spring真的太方便了。
分享到:
评论

相关推荐

    velocity中文

    class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader ``` ### 5. Velocity与MVC框架的集成 Velocity可以轻松地与Spring MVC、Struts等主流Java Web框架集成,提供...

    Velocity配置文件详解

    - **file.resource.loader.class**:加载器类名称,默认为`org.apache.velocity.runtime.resource.loader.FileResourceLoader`。 - **file.resource.loader.path**:模板文件所在的路径,默认为`.`表示当前目录。 - ...

    velocity-engine-core-2.0.jar

    // Template t = ve.getTemplate("src/velocity/hellovelocity.vm"); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); // 在类路径下加载 ve.setProperty("classpath.resource.loader.class...

    velocity-1.5.jar,velocity-1.6.2-dep.jar,velocity-tools-1.3.jar

    Velocity是Apache软件基金会的一个开源项目,它是一款强大的模板引擎,主要用于生成动态Web内容。 Velocity的主要优点在于其简单易用和高度可扩展性,使得开发者能够将业务逻辑与表现层分离,提高代码的可读性和维护...

    Velocity模板引擎Velocity模板引擎

    Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎

    velocity-tools-2.0.jar

    velocity-tools-2.0.jar velocity-tools-2.0.jar velocity-tools-2.0.jar velocity-tools-2.0.jar velocity-tools-2.0.jar

    velocity-1.7.jar

    3. **Resource Loader**:扩展了Velocity的资源加载机制,使其能够从多种来源(如文件系统、数据库等)加载模板。 4. **MVC框架集成**:如Struts、Spring MVC等,提供与这些流行MVC框架的集成。 在实际项目中,将...

    velocity的jar包

    **Velocity简介** Velocity是Apache软件基金会的一个开源项目,它是一个基于Java的模板引擎,用于生成动态网站内容。Velocity被设计成一个轻量级的、快速的、非侵入式的模板语言,使得开发者能够将HTML页面的展示...

    JAVA的Velocity语法学习

    6. 引用资源:Velocity可以使用`#resource`指令加载外部资源,如模板文件。 ** Velocity模板引擎的应用 ** 1. Web应用:Velocity常被用于MVC框架中,作为视图层的模板引擎,将数据模型与HTML模板结合,生成动态...

    Velocity本地化应用举例

    velocityProperties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); velocityProperties.setProperty("velocimacro.library", ""); ...

    velocity插件

    【 Velocity 插件详解】 Velocity 是一款基于 Java 的模板引擎,它被广泛应用于 Web 开发中,特别是作为 Apache Struts 和 Spring MVC 框架的一部分。Velocity 插件则是为了在开发环境中提供对 Velocity 模板语言的...

    velocity为空判断

    这两个指令属于Velocity Tools的扩展,如果你的项目中引入了Velocity Tools,可以通过在`velocity.properties`文件中添加以下配置来启用它们: ```properties userdirective = org.apache.velocity.tools.generic....

    92.Spring Boot使用模板velocity【从零开始学Spring Boot】

    spring.velocity.properties.classpath.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader spring.velocity.view.prefix=/templates/ spring.velocity.view.suffix=....

    velocity.pdf

    p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); VelocityEngine ve = new VelocityEngine(); ve.init(p); Template t = ve.getTemplate...

    velocity Java开发指南中文版

    - **Why Can't I see My Changes? 为什么我看不到我的更改?**: 一个常见问题,解释了为什么在修改模板后可能看不到即时效果的原因及解决办法。 - **Other Common Issues 其他常见问题**: 列举了一些开发者在使用 ...

    Velocity1.4

    Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity

    velocity所需的jar包

    `eclipse相关插件`,虽然不是必需的jar包,但对于使用Eclipse作为IDE的开发者来说,可能需要安装Velocity支持的Eclipse插件,如Velocity视图插件,它能提供模板语法高亮和代码完成等功能,提高开发效率。 为了正确...

    Velocity资料

    资源装载器(Resource Loaders)是Velocity用来加载模板和资源的机制,文档中提到了自定义资源装载器和缓存实现的插入。 15. Velocity字符编码问题: 对于国际化应用,字符编码问题尤为重要,文档中提到了Velocity...

    Velocity 和 FreeMarker区别

    ### Velocity与FreeMarker的区别 在IT领域特别是Java开发中,模板引擎是不可或缺的一部分,它们用于将数据模型转换为HTML、PDF、Word文档等格式。在众多模板引擎中,Velocity和FreeMarker是两种非常受欢迎的选择。...

    模板:velocity和freemarker的比较

    Velocity和Freemarker模板技术比较 模板技术在现代软件开发中扮演着重要角色,而在目前最流行的两种模板技术中, Velocity 和 Freemarker 独占鳌头。在 WebWork2 中,我们可以随意选择使用 Freemarker 或 Velocity ...

Global site tag (gtag.js) - Google Analytics