をありがとう、私は私のサービス・クラスで実際のパスを渡すためにしようと
public class EmailSender {
public static boolean send(String to, String newUsername, String newPassword, String contentPath) {
try{
.......................
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
context.put("username", newUsername);
context.put("password", newPassword);
Template t = ve.getTemplate(contentPath);
StringWriter writer = new StringWriter();
t.merge(context, writer);
System.out.println(writer.toString());
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
:なぜ
私の電子メールの送信のクラス、そのようなこと my spring xml(applicationContext.xml)
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<props>
<prop key="resource.loader">class</prop>
<prop key="class.resource.loader.class">
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</prop>
</props>
</property>
</bean>
<bean id="emailSender" class="com.satunol.pms.helper.EmailSender">
<property name="velocityEngine"><ref bean="velocityEngine"/></property>
</bean>
リソースフォルダに入れ私のemailFormatで 私の電子メールの送信のクラスで
private VelocityEngine velocityEngine;
public void setVelocityEngine(VelocityEngine velocityEngine) {
this.velocityEngine = velocityEngine;
}
......................
Template t = velocityEngine.getTemplate("emailFormat.vm");
StringWriter writer = new StringWriter();
System.out.println(writer.toString());
に(WEB-INF /クラス)
ありがとう
を点滅あなたは[ベロシティリソースローダー](HTTPを見てきました://velocity.apache.org/engine/releases/velocity-1.5/developer-guide.html#configuring_resource_loaders)? – flash
pathContentとは何ですか?絶対パス?ベロシティエンジンを正しく設定しましたか?詳細を記入してください。 –
私は絶対パスを渡す、私は私の質問を編集しました。この場合、私はちょうどそのコンテンツを書くことを試みる –