25
25
import org .activiti .spring .SpringProcessEngineConfiguration ;
26
26
import org .springframework .beans .factory .annotation .Autowired ;
27
27
import org .springframework .beans .factory .annotation .Value ;
28
+ import org .springframework .boot .context .properties .ConfigurationProperties ;
29
+ import org .springframework .boot .jdbc .DataSourceBuilder ;
28
30
import org .springframework .context .ApplicationContext ;
29
31
import org .springframework .context .annotation .Bean ;
30
32
import org .springframework .context .annotation .Configuration ;
31
33
import org .springframework .core .io .Resource ;
32
34
import org .springframework .core .io .ResourceLoader ;
33
35
import org .springframework .core .io .support .PathMatchingResourcePatternResolver ;
36
+ import org .springframework .jdbc .datasource .DataSourceTransactionManager ;
34
37
import org .springframework .transaction .PlatformTransactionManager ;
35
- import org .springframework .transaction .TransactionManager ;
36
38
37
39
/** Activiti configuration class. */
38
40
@ Configuration
39
41
public class ActivitiConfig {
40
42
41
- private final DataSource dataSource ;
42
-
43
- private final TransactionManager transactionManager ;
44
-
45
43
private final ApplicationContext applicationContext ;
46
44
47
45
@ Value ("${spring.activiti.history-level}" )
@@ -50,23 +48,30 @@ public class ActivitiConfig {
50
48
/** constructor for ActivitiConfig bean. */
51
49
@ Autowired
52
50
public ActivitiConfig (
53
- DataSource dataSource ,
54
- TransactionManager transactionManager ,
55
51
ApplicationContext applicationContext ) {
56
- this .dataSource = dataSource ;
57
- this .transactionManager = transactionManager ;
58
52
this .applicationContext = applicationContext ;
59
53
}
60
54
55
+
56
+ @ Bean (name = "activitiDataSource" )
57
+ @ ConfigurationProperties (prefix = "spring.activiti.datasource" )
58
+ public DataSource activitiDataSource () {
59
+ return DataSourceBuilder .create ().build ();
60
+ }
61
+
62
+ @ Bean (name = "activitiTransactionManager" )
63
+ public PlatformTransactionManager activitiTransactionManager () {
64
+ return new DataSourceTransactionManager (activitiDataSource ());
65
+ }
66
+
61
67
/** Create ProcessEngineConfiguration object into SpringIoc. */
62
68
@ Bean
63
69
public ProcessEngineConfiguration processEngineConfiguration () throws IOException {
64
70
SpringProcessEngineConfiguration springProcessEngineConfiguration =
65
71
new SpringProcessEngineConfiguration ();
66
72
springProcessEngineConfiguration .setIdGenerator (strongUuidGenerator ());
67
- springProcessEngineConfiguration .setDataSource (dataSource );
68
- springProcessEngineConfiguration .setTransactionManager (
69
- (PlatformTransactionManager ) transactionManager );
73
+ springProcessEngineConfiguration .setDataSource (activitiDataSource ());
74
+ springProcessEngineConfiguration .setTransactionManager (activitiTransactionManager ());
70
75
springProcessEngineConfiguration .setDatabaseSchemaUpdate ("true" );
71
76
springProcessEngineConfiguration .setDeploymentMode ("single-resource" );
72
77
Resource [] resources =
0 commit comments