隨筆-153  評論-235  文章-19  trackbacks-0

              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.aygfsteel.com/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.aygfsteel.com/chenlb"></property>
              
          </bean>

          resourceLoaderPath是由Spring設置過的,跟平常的(Spring)文件資源一樣方式引用,Spring真的太方便了。
          posted on 2007-08-18 02:11 流浪汗 閱讀(3741) 評論(0)  編輯  收藏 所屬分類: OpenSource
          主站蜘蛛池模板: 大方县| 井冈山市| 屯昌县| 沈丘县| 宣武区| 温泉县| 扶风县| 镇远县| 湖州市| 宜川县| 滨海县| 株洲县| 冀州市| 阿合奇县| 宝山区| 建始县| 松潘县| 双流县| 陆良县| 广河县| 刚察县| 三原县| 紫金县| 盐源县| 太仓市| 湾仔区| 长沙县| 东丽区| 南木林县| 平果县| 鄂尔多斯市| 安吉县| 怀集县| 准格尔旗| 浦东新区| 平果县| 道孚县| 敖汉旗| 洪湖市| 黎平县| 龙里县|