我创建了一个eclipse maven项目,假设在Activti bpm中启动serviceTask,向给定用户发送电子邮件。
我使用apache James服务器并将其配置为gmail,我能够通过telnet发送电子邮件,但不能使用我的服务任务。
问题是我的配置被apache commons中的一个名为Email的类覆盖。 我不明白为什么要调用这个类,我不会在我的java代码中使用apache.commons。
James配置:config.xml
<servernames autodetect="true" autodetectIP="true">
<servername>smtp.gmail.com</servername>
</servernames>
<dnsserver>
<servers>
<!--Enter ip address of your DNS server, one IP address per server -->
<!-- element. -->
<!--
<server>127.0.0.1</server>
-->
<server> 8.8.8.8 </server>
<server> 8.8.4.4 </server>
</servers>
<!-- Change autodiscover to false if you would like to turn off autodiscovery -->
<!-- and set the DNS servers manually in the <servers> section -->
<autodiscover>true</autodiscover>
<authoritative>false</authoritative>
<!-- Maximum number of entries to maintain in the DNS cache -->
<maxcachesize>50000</maxcachesize>
</dnsserver>
...
smtpserver enabled="true">
<port>587</port>
...
这是包含流程定义的bpmn20.xml:
<definitions id="definitions"
targetNamespace="http://activiti.org/bpmn20"
xmlns:activiti="http://activiti.org/bpmn"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
<process id="EmailNotification" name="emailNotification">
<documentation>Simple Email Notification Task</documentation>
<startEvent id="startevent1" name="Start"></startEvent>
<sequenceFlow id="flow1" name="" sourceRef="startevent1"
targetRef="mailtask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow2" name="" sourceRef="mailtask1"
targetRef="endevent1"></sequenceFlow>
<serviceTask id="mailtask1" name="Email Notification"
activiti:type="mail">
<extensionElements>
<activiti:field name="to" expression="workflowact@gmail.com"
></activiti:field>
<activiti:field name="from" expression="no-reply@forgerock.com"
></activiti:field>
<activiti:field name="subject" expression="Simple Email Notification"
></activiti:field>
<activiti:field name="html">
<activiti:expression><![CDATA[Here is a simple Email Notification
from a user.]]></activiti:expression>
</activiti:field>
</extensionElements>
</serviceTask>
</process>
</definitions>
这是java代码:
// Create Activiti process engine
ProcessEngine processEngine = ProcessEngineConfiguration
.createStandaloneInMemProcessEngineConfiguration()
.buildProcessEngine();
// Get Activiti services
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
// Deploy the process definition
repositoryService.createDeployment()
.addClasspathResource("risk.bpmn20.xml")
.deploy();
// Start a process instance
String procId =
runtimeService.startProcessInstanceByKey("EmailNotification").getId();
这是activiti.cfg.xml文件:
<?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.xsd">
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration" >
<!-- Database configurations -->
<property name="databaseType" value="h2" />
<property name="jdbcUrl
value="jdbc:h2:C:/Users/Alexandra/tmp/activiti;AUTO_SERVER=TRUE" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />
<!-- Database configurations -->
<property name="databaseSchemaUpdate" value="true" />
<!-- job executor configurations -->
<property name="jobExecutorActivate" value="true" />
<!-- mail server configurations -->
<property name="mailServerHost" value="smtp.gmail.com" />
<property name="mailServerPort" value="587" />
<property name="mailServerUsername" value="root" />
<property name="mailServerPassword" value="root" />
<property name="history" value="full" />
<property name="customPostDeployers">
<list>
<bean class="org.activiti.engine.impl.rules.RulesDeployer" />
</list>
</property>
</bean>
</beans>
答案 0 :(得分:0)
现在解决了这个问题。我通过设置流程引擎的数据来解决它。
ProcessEngine processEngine = ProcessEngineConfiguration
.createStandaloneInMemProcessEngineConfiguration()
.setMailServerHost("smtp.gmail.com")
.setMailServerPort(587)
.setMailServerUsername("root")
.setMailServerPassword("root")
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
.setMailServerUseSSL(true)
.setMailServerUseTLS(true)
.setMailServerDefaultFrom("workflowact@gmail.com")
.buildProcessEngine();