Что является лучшим подходом для использования компонента скорости внутри контейнера пружины.
В моем классе speed util (emailer) я объявил метод отправки электронной почты как STATIC, чтобы избежать создания объекта emailer каждый раз.Также я объявил инъекции сеттера как статические.
Это правильный путь?
Java:
Class emailer{
public static Boolean sendEmail(){
SimpleMailMessage msg = new SimpleMailMessage();
String val = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template, model);
msg.setText(val);
mailSender.send(msg);
}
private static MailSender mailSender;
@Autowired
public static void setMailSender(MailSender mailsender) {
LOGGER.debug("MailSender set successfully");
mailSender = mailsender;
}
private static VelocityEngine velocityEngine;
@Autowired
public static void setVelocityEngine(VelocityEngine velocityengine) {
LOGGER.debug("Velocity Engine set successfully");
velocityEngine = velocityengine;
}
}
xml изменения: localhost
<bean id="emailHelper" class="emailer">
<property name="mailSender" ref="mailSender"/>
<property name="velocityEngine" ref="velocityEngine"/>
<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>