2017-10-14 25 views
0
I went through the documentation of Broadleaf to send Email confirmation 
Below is my applicationcontext-email.xml file 

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"> 

    <!-- A dummy mail sender has been set to send emails for testing purposes 
     only To view the emails sent use "DevNull SMTP" (download separately) with 
     the following setting: Port: 30000 --> 


    <!-- Broadleaf step 3 --> 
    <bean id="blServerInfo" 
     class="org.broadleafcommerce.common.email.service.info.ServerInfo"> 
     <property name="serverName" value="smtp.office365.com" /> 
     <property name="serverPort" value="587" /> 
    </bean> 

    <bean id="blEmailTemplateResolver" 
     class="org.thymeleaf.templateresolver.ClassLoaderTemplateResolver"> 
     <property name="prefix" value="emailTemplates/" /> 
     <property name="suffix" value=".html" /> 
     <property name="cacheable" value="${cache.page.templates}" /> 
     <property name="cacheTTLMs" value="${cache.page.templates.ttl}" /> 
    </bean> 

    <bean id="blEmailTemplateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"> 
     <property name="templateResolvers"> 
      <set> 
       <ref bean="blEmailTemplateResolver" /> 
      </set> 
     </property> 
     <property name="dialects"> 
      <set> 
       <bean class="org.thymeleaf.spring4.dialect.SpringStandardDialect" /> 
       <ref bean="blDialect" /> 
      </set> 
     </property> 
    </bean> 

    <!-- Broadleaf email step 1 --> 
    <bean id="blMessageCreator" 
     class="org.broadleafcommerce.common.email.service.message.ThymeleafMessageCreator"> 
     <constructor-arg ref="blEmailTemplateEngine" /> 
     <constructor-arg ref="blMailSender" /> 
    </bean> 


    <bean id="blEmailInfo" 
     class="org.broadleafcommerce.common.email.service.info.EmailInfo"> 
     <property name="fromAddress"> 
      <value>m[email protected]</value> 
     </property> 
     <property name="sendAsyncPriority"> 
      <value>2</value> 
     </property> 
     <property name="sendEmailReliableAsync"> 
      <value>false</value> 
     </property> 
    </bean> 

    <bean id="blMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 
     <property name="host"> 
      <value>localhost</value> 
     </property> 
     <property name="port"> 
      <value>30000</value> 
     </property> 
     <property name="protocol"> 
      <value>smtp</value> 
     </property> 
     <property name="username"> 
      <value>gaurav</value> 
     </property> 
     <property name="password"> 
      <value>mypassword</value> 
     </property> 
     <property name="javaMailProperties"> 
      <props> 
       <prop key="mail.smtp.starttls.enable">true</prop> 
       <prop key="mail.smtp.timeout">25000</prop> 
      </props> 
     </property> 
    </bean> 










    <bean id="blVelocityEngine" 
     class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> 
     <property name="resourceLoaderPath" value="/WEB-INF/emailTemplates/" /> 
     <property name="velocityProperties"> 
      <value> 
       resource.loader=file,class 
       class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 
       runtime.references.strict = false 
      </value> 
     </property> 
    </bean> 

    <bean id="blMessageCreator" 
     class="org.broadleafcommerce.common.email.service.message.VelocityMessageCreator"> 
     <constructor-arg ref="blVelocityEngine" /> 
     <constructor-arg ref="blMailSender" /> 
     <constructor-arg> 
      <map> 
       <entry key="number"> 
        <bean class="org.apache.velocity.tools.generic.NumberTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="date"> 
        <bean class="org.apache.velocity.tools.generic.ComparisonDateTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="list"> 
        <bean class="org.apache.velocity.tools.generic.ListTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="math"> 
        <bean class="org.apache.velocity.tools.generic.MathTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="iterator"> 
        <bean class="org.apache.velocity.tools.generic.IteratorTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="alternator"> 
        <bean class="org.apache.velocity.tools.generic.AlternatorTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="sorter"> 
        <bean class="org.apache.velocity.tools.generic.SortTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="esc"> 
        <bean class="org.apache.velocity.tools.generic.EscapeTool" 
         scope="prototype" /> 
       </entry> 
       <entry key="serverInfo" value-ref="blServerInfo" /> 
      </map> 
     </constructor-arg> 
    </bean> 



    <!-- <bean id="blMessageCreator" class="org.broadleafcommerce.common.email.service.message.NullMessageCreator"> 
     <constructor-arg ref="blMailSender"/> </bean> --> 





    <bean id="blRegistrationEmailInfo" parent="blEmailInfo"> 
     <property name="subject" value="You have successfully registered!" /> 
     <property name="emailTemplate" value="register-email" /> 
    </bean> 

    <bean id="blForgotPasswordEmailInfo" parent="blEmailInfo"> 
     <property name="subject" value="Reset password request" /> 
     <property name="emailTemplate" value="resetPassword-email" /> 
    </bean> 

    <!-- Broadleaf email step 2 --> 
    <bean id="orderConfirmationEmailInfo" class="org.broadleafcommerce.common.email.service.info.EmailInfo" parent="blEmailInfo" scope="prototype"> 
    <property name="messageBody" value="This is a test email!"/> 
    <property name="emailType" value="ORDERCONFIRMATION"/> 
    <property name="subject" value="Thank You For Your Order!"/> 
</bean> 

</beans> 

I have also created an activity as mentioned in the documentation: 
package com.mycompany.worklow.emailactivity; 

import javax.annotation.Resource; 

import org.broadleafcommerce.core.checkout.service.workflow.CheckoutSeed; 
import org.broadleafcommerce.core.checkout.service.workflow.CompleteOrderActivity; 
import org.broadleafcommerce.core.order.domain.Order; 
import org.broadleafcommerce.core.workflow.ProcessContext; 

import com.mycompany.service.MyEmailWebService; 

    enter code here 

    public class MyCompleteOrderActivity extends CompleteOrderActivity { 

     @Resource(name="myEmailService") 
     protected MyEmailWebService myEmailService; 

     @Override 
     public ProcessContext execute(ProcessContext context) throws Exception { 

      CheckoutSeed seed = (CheckoutSeed) context.getSeedData(); 

      Order order = seed.getOrder(); 
      myEmailService.sendOrderConfirmation(order.getSubmitDate(), order.getId().toString(), order.getCustomer().getEmailAddress()); 
      return super.execute(context); 
     } 
     } 
} 

는 또한 애플리케이션 컨텍스트 - workflow.xml보내기 주문 확인 이메일 - 잎이 넓은 담배가

내가 exxception 이하이 무엇입니까에서이 활동을 추가 : 소스와 패치 위치를 병합 할 수 없습니다; 중첩 예외는 org.broadleafcommerce.common.extensibility.context.merge.exceptions.MergeException입니다 : java.lang.NullPointerException

아무도 단계를 구현하여 단계를 설명 할 수 있습니까? 미리 감사드립니다.

답변

0

콩 이름이 blMessageCreator 인 경우 그 중 하나를 제거해야합니다. thymeleaf 템플릿을 사용하는 버전 5 데모 사이트를 사용한다고 가정하고 다음을 제거해보십시오.

<bean id="blMessageCreator" class="org.broadleafcommerce.common.email.service.message.VelocityMessageCreator"> 
... 
... 
</bean>