提交 0d2d35b9 编写于 作者: J Joram Barrez

[Spring Boot] Adding JPA integration

上级 59ac7f5b
......@@ -19,6 +19,7 @@
<module>spring-boot-starter-integration</module>
<module>spring-boot-starter-actuator</module>
<module>spring-boot-starter-security</module>
<module>spring-boot-starter-jpa</module>
</modules>
<dependencies>
<dependency>
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.activiti</groupId>
<artifactId>spring-boot-starters</artifactId>
<version>5.16.4-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-starter-jpa</artifactId>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>spring-boot-starters-basic</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency> -->
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.spring.boot;
import javax.persistence.EntityManagerFactory;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
/**
*
* Auto-configuration and starter for the Activiti + JPA integration
*
*/
@Configuration
@AutoConfigureAfter( BasicProcessEngineAutoConfiguration.class)
public class ProcessEngineJpaAutoConfiguration {
@Configuration
@ConditionalOnExpression("${spring.activiti.isJpaEnabled:true}")
@ConditionalOnClass(value={EntityManagerFactory.class})
public static class JpaIntegrationAutoConfiguration {
@Autowired
private ActivitiProperties activitiProperties;
@Autowired
private EntityManagerFactory emf;
@Autowired
private SpringProcessEngineConfiguration processEngineAutoConfiguration;
@Primary
@ConditionalOnMissingBean
@Bean
public PlatformTransactionManager jpaTransactionManager() {
return new JpaTransactionManager(emf);
}
@Primary // We need to inject the entitymanagerFactory and transactionmanager first, before construction the engine
@Bean
public ProcessEngineFactoryBean processEngine() throws Exception { // configureJpaForActiviti() -> hack to get the order right (c
System.out.println("BLAH - JPA");
processEngineAutoConfiguration.setJpaEntityManagerFactory(emf);
processEngineAutoConfiguration.setJpaHandleTransaction(false);
processEngineAutoConfiguration.setJpaCloseEntityManager(false);
processEngineAutoConfiguration.setTransactionManager(jpaTransactionManager());
ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
processEngineFactoryBean.setProcessEngineConfiguration(processEngineAutoConfiguration);
return processEngineFactoryBean;
}
// @Bean
// public InitializingBean configureJpaForActiviti() {
// return new InitializingBean() {
//
// @Override
// public void afterPropertiesSet() throws Exception {
// if (activitiProperties.isJpaEnabled()) {
// System.out.println("TEST2");
// System.out.println("TEST2");
// System.out.println("TEST2");
// System.out.println("TEST2");
// System.out.println("TEST2");
// System.out.println("TEST2");
// System.out.println("TEST2");
// processEngineAutoConfiguration.setJpaEntityManagerFactory(emf);
// processEngineAutoConfiguration.setJpaHandleTransaction(false);
// processEngineAutoConfiguration.setJpaCloseEntityManager(false);
// processEngineAutoConfiguration.setTransactionManager(jpaTransactionManager());
//
// // TODO: build order? Are we sure the Process Engine gets built AFTER this?
//// processEngineAutoConfiguration.initJpaAfterProcessEngineIsBuilt(emf, false, false);
// }
// }
// };
// }
}
}
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.activiti.spring.boot.ProcessEngineJpaAutoConfiguration
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" xmlns:modeler="http://activiti.com/modeler" modeler:version="1.0en" modeler:exportDateTime="20140917221847386" modeler:modelId="1000" modeler:modelVersion="1" modeler:modelLastUpdated="1410985124511">
<process id="dogeProcess" name="Webinar process" isExecutable="true">
<startEvent id="startEvent1"/>
<subProcess id="sid-9A0D8C79-52E9-4C8E-9264-2F7E20524759" name="subProcess">
<multiInstanceLoopCharacteristics isSequential="false" activiti:collection="photos" activiti:elementVariable="photoId" />
<serviceTask id="sendPhotoTask" name="Send photo to transformation queue" activiti:expression="${photoService.processPhoto(photoId)}"/>
<!-- <serviceTask id="sendPhotoTask" name="Send photo to transformation queue" activiti:class="org.activiti.SomeClass"/> -->
<receiveTask id="wait" name="Wait for transformation response"/>
<startEvent id="sid-468797D3-BB35-432F-BD71-F876973359A0"/>
<sequenceFlow id="sid-BDF6C58B-6D84-41EF-BA6F-4329FB17D15E" sourceRef="sendPhotoTask" targetRef="wait"/>
<sequenceFlow id="sid-77D10479-52EC-4926-82E0-5F89C49B5E1C" sourceRef="sid-468797D3-BB35-432F-BD71-F876973359A0" targetRef="sendPhotoTask"/>
</subProcess>
<sequenceFlow id="sid-219A7058-127A-4225-92EF-A1DD1BF26185" sourceRef="startEvent1" targetRef="sid-9A0D8C79-52E9-4C8E-9264-2F7E20524759"/>
<userTask id="sid-D0881E5F-D9E8-42F1-AF40-46BAB0720B95" name="Review results" activiti:candidateGroups="reviewers"/>
<sequenceFlow id="sid-D1FD0A98-3D1D-478E-A014-D21F3C6001F1" sourceRef="sid-9A0D8C79-52E9-4C8E-9264-2F7E20524759" targetRef="sid-D0881E5F-D9E8-42F1-AF40-46BAB0720B95"/>
<exclusiveGateway id="sid-61BE5E6B-3C28-4946-BF05-EC29390F729F" default="sid-140521E0-9D8C-49E5-B2A9-A724147CB51C"/>
<sequenceFlow id="sid-4A0107D5-A509-48ED-A0AD-811971ADF9B7" sourceRef="sid-D0881E5F-D9E8-42F1-AF40-46BAB0720B95" targetRef="sid-61BE5E6B-3C28-4946-BF05-EC29390F729F"/>
<serviceTask id="sid-9CE96F9A-6A75-4339-AE6E-656975D6CB85" name="Send fail mail to uploader" activiti:type="mail">
<extensionElements>
<activiti:field name="to">
<activiti:expression>${uploaderEmail}</activiti:expression>
</activiti:field>
<activiti:field name="from">
<activiti:string><![CDATA[no-reply@activiti.org]]></activiti:string>
</activiti:field>
<activiti:field name="subject">
<activiti:string><![CDATA[Sorry, we couldn't upload your photos]]></activiti:string>
</activiti:field>
<activiti:field name="text">
<activiti:string><![CDATA[We're very sorry, but we deemed your photos inappropriate]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
<endEvent id="sid-DA3457B6-7DA4-44C6-919F-06FE64A06624" name="all perfect"/>
<endEvent id="sid-B9CE518F-106B-47D8-A61F-88CA58AB90BC" name="photos not good&#xa;"/>
<sequenceFlow id="sid-AB78E174-F8ED-48D7-BE43-E4EBE79AE607" sourceRef="sid-9CE96F9A-6A75-4339-AE6E-656975D6CB85" targetRef="sid-B9CE518F-106B-47D8-A61F-88CA58AB90BC"/>
<sequenceFlow id="sid-36D71090-415E-4D75-ACAE-C4E2C566B2BF" name="not approved" sourceRef="sid-61BE5E6B-3C28-4946-BF05-EC29390F729F" targetRef="sid-9CE96F9A-6A75-4339-AE6E-656975D6CB85">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${!approved}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-140521E0-9D8C-49E5-B2A9-A724147CB51C" sourceRef="sid-61BE5E6B-3C28-4946-BF05-EC29390F729F" targetRef="sid-DA3457B6-7DA4-44C6-919F-06FE64A06624"/>
<boundaryEvent id="sid-E479C1B9-A618-4E72-BCE6-6468D9610293" attachedToRef="sid-9A0D8C79-52E9-4C8E-9264-2F7E20524759" cancelActivity="true">
<timerEventDefinition>
<timeDuration>PT10M</timeDuration>
</timerEventDefinition>
</boundaryEvent>
<serviceTask id="sid-3AEF1482-EC8D-4ABE-B73B-FDE20EDFA396" name="Send fail mail to uploader" activiti:type="mail">
<extensionElements>
<activiti:field name="to">
<activiti:expression>${uploaderEmail}</activiti:expression>
</activiti:field>
<activiti:field name="from">
<activiti:string><![CDATA[no-reply@activiti.org]]></activiti:string>
</activiti:field>
<activiti:field name="subject">
<activiti:string><![CDATA[Sorry, we couldn't upload your photos]]></activiti:string>
</activiti:field>
<activiti:field name="text">
<activiti:string><![CDATA[We're very sorry, but we couldm't process your photos]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
<sequenceFlow id="sid-61A74365-569A-4260-947F-A5E20CA3F962" sourceRef="sid-E479C1B9-A618-4E72-BCE6-6468D9610293" targetRef="sid-3AEF1482-EC8D-4ABE-B73B-FDE20EDFA396"/>
<endEvent id="sid-B1497346-48C8-4ABC-8B30-14798D8BA30A"/>
<sequenceFlow id="sid-B77D1FB2-6781-458E-89E3-0DB3B7EFA858" sourceRef="sid-3AEF1482-EC8D-4ABE-B73B-FDE20EDFA396" targetRef="sid-B1497346-48C8-4ABC-8B30-14798D8BA30A"/>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_webinarprocess">
<bpmndi:BPMNPlane bpmnElement="webinarprocess" id="BPMNPlane_webinarprocess">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="45.0" y="367.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-9A0D8C79-52E9-4C8E-9264-2F7E20524759" id="BPMNShape_sid-9A0D8C79-52E9-4C8E-9264-2F7E20524759">
<omgdc:Bounds height="271.0" width="424.0" x="150.0" y="246.5"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sendPhotoTask" id="BPMNShape_sendPhotoTask">
<omgdc:Bounds height="89.0" width="125.0" x="225.0" y="337.5"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="wait" id="BPMNShape_wait">
<omgdc:Bounds height="85.0" width="113.0" x="405.0" y="339.5"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-468797D3-BB35-432F-BD71-F876973359A0" id="BPMNShape_sid-468797D3-BB35-432F-BD71-F876973359A0">
<omgdc:Bounds height="30.0" width="30.0" x="165.0" y="363.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-D0881E5F-D9E8-42F1-AF40-46BAB0720B95" id="BPMNShape_sid-D0881E5F-D9E8-42F1-AF40-46BAB0720B95">
<omgdc:Bounds height="78.0" width="115.0" x="615.0" y="343.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-61BE5E6B-3C28-4946-BF05-EC29390F729F" id="BPMNShape_sid-61BE5E6B-3C28-4946-BF05-EC29390F729F">
<omgdc:Bounds height="40.0" width="40.0" x="775.0" y="362.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-9CE96F9A-6A75-4339-AE6E-656975D6CB85" id="BPMNShape_sid-9CE96F9A-6A75-4339-AE6E-656975D6CB85">
<omgdc:Bounds height="80.0" width="100.0" x="855.0" y="210.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-DA3457B6-7DA4-44C6-919F-06FE64A06624" id="BPMNShape_sid-DA3457B6-7DA4-44C6-919F-06FE64A06624">
<omgdc:Bounds height="28.0" width="28.0" x="870.0" y="368.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-B9CE518F-106B-47D8-A61F-88CA58AB90BC" id="BPMNShape_sid-B9CE518F-106B-47D8-A61F-88CA58AB90BC">
<omgdc:Bounds height="28.0" width="28.0" x="1020.0" y="236.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-E479C1B9-A618-4E72-BCE6-6468D9610293" id="BPMNShape_sid-E479C1B9-A618-4E72-BCE6-6468D9610293">
<omgdc:Bounds height="31.0" width="31.0" x="475.3101185693114" y="502.14287535000176"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-3AEF1482-EC8D-4ABE-B73B-FDE20EDFA396" id="BPMNShape_sid-3AEF1482-EC8D-4ABE-B73B-FDE20EDFA396">
<omgdc:Bounds height="80.0" width="100.0" x="525.0" y="600.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-B1497346-48C8-4ABC-8B30-14798D8BA30A" id="BPMNShape_sid-B1497346-48C8-4ABC-8B30-14798D8BA30A">
<omgdc:Bounds height="28.0" width="28.0" x="670.0" y="626.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-77D10479-52EC-4926-82E0-5F89C49B5E1C" id="BPMNEdge_sid-77D10479-52EC-4926-82E0-5F89C49B5E1C">
<omgdi:waypoint x="194.98962677895514" y="378.55775355456575"/>
<omgdi:waypoint x="225.0" y="379.6744186046512"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-36D71090-415E-4D75-ACAE-C4E2C566B2BF" id="BPMNEdge_sid-36D71090-415E-4D75-ACAE-C4E2C566B2BF">
<omgdi:waypoint x="795.5" y="362.5"/>
<omgdi:waypoint x="795.5" y="250.0"/>
<omgdi:waypoint x="855.0" y="250.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-D1FD0A98-3D1D-478E-A014-D21F3C6001F1" id="BPMNEdge_sid-D1FD0A98-3D1D-478E-A014-D21F3C6001F1">
<omgdi:waypoint x="574.0" y="382.0"/>
<omgdi:waypoint x="615.0" y="382.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-4A0107D5-A509-48ED-A0AD-811971ADF9B7" id="BPMNEdge_sid-4A0107D5-A509-48ED-A0AD-811971ADF9B7">
<omgdi:waypoint x="730.0" y="382.2337398373984"/>
<omgdi:waypoint x="775.4183673469388" y="382.4183673469388"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-AB78E174-F8ED-48D7-BE43-E4EBE79AE607" id="BPMNEdge_sid-AB78E174-F8ED-48D7-BE43-E4EBE79AE607">
<omgdi:waypoint x="955.0" y="250.0"/>
<omgdi:waypoint x="1020.0" y="250.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-61A74365-569A-4260-947F-A5E20CA3F962" id="BPMNEdge_sid-61A74365-569A-4260-947F-A5E20CA3F962">
<omgdi:waypoint x="491.3101185693114" y="534.1428753500018"/>
<omgdi:waypoint x="491.3101185693114" y="640.0"/>
<omgdi:waypoint x="525.0" y="640.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-140521E0-9D8C-49E5-B2A9-A724147CB51C" id="BPMNEdge_sid-140521E0-9D8C-49E5-B2A9-A724147CB51C">
<omgdi:waypoint x="814.6079545454545" y="382.39204545454544"/>
<omgdi:waypoint x="870.0002234298072" y="382.07909478288246"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-B77D1FB2-6781-458E-89E3-0DB3B7EFA858" id="BPMNEdge_sid-B77D1FB2-6781-458E-89E3-0DB3B7EFA858">
<omgdi:waypoint x="625.0" y="640.0"/>
<omgdi:waypoint x="670.0" y="640.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-BDF6C58B-6D84-41EF-BA6F-4329FB17D15E" id="BPMNEdge_sid-BDF6C58B-6D84-41EF-BA6F-4329FB17D15E">
<omgdi:waypoint x="350.0" y="382.0"/>
<omgdi:waypoint x="405.0" y="382.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-219A7058-127A-4225-92EF-A1DD1BF26185" id="BPMNEdge_sid-219A7058-127A-4225-92EF-A1DD1BF26185">
<omgdi:waypoint x="75.0" y="382.0"/>
<omgdi:waypoint x="150.0" y="382.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册