gpt4 book ai didi

java - 基于注解的Spring Activiti ProcessEngine

转载 作者:行者123 更新时间:2023-12-01 12:00:39 26 4
gpt4 key购买 nike

我对 Spring 和 Activiti 还很陌生。我正在开发带有嵌入式 Activiti 引擎的基于注释的 Spring Web 应用程序。我实现了一些服务,SubscriptionService 就是其中之一。在一个进程中,我将该服务称为 bean:

activiti:expression="${subscriptionService.getContacts(publisherCode, contactType)}"

服务:

@Service
@Transactional
public class DBSubscriptionService implements SubscriptionService {
...
}

我已经分离了测试模块和网络模块。测试模块从 activiti.cfg.xml 加载上下文

@ContextConfiguration("classpath:activiti.cfg.xml")

它是:

<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="databaseType" value="h2" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
<property name="history" value="full" />
<property name="mailServerPort" value="2025" />
</bean>

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<bean id="identityService" factory-bean="processEngine"
factory-method="getIdentityService" />
<bean id="formService" factory-bean="processEngine"
factory-method="getFormService" />

<context:component-scan base-package="cz.muni.fi.cep" />
<context:annotation-config />

在测试模块中,一切正常。但是在 Web 模块中,当它应该调用 subscriptionService Bean 时,它会抛出:

    Unknown property used in expression: ${subscriptionService.getContacts(publisherCode, contactType)}
Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'subscriptionService'
at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)
at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:79)
at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26)
at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114)
at org.activiti.engine.impl.delegate.ExpressionGetInvocation.invoke(ExpressionGetInvocation.java:33)
at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:48)
... 363 more

所以我理解问题是流程引擎没有使用正确的应用程序上下文,因为订阅服务可以很好地自动连接到其他类。但我不知道如何解决它。

Web 模块纯粹基于注释:

@EnableAutoConfiguration
@Configuration
@EntityScan(basePackages = "cz.muni.fi.cep")
@ComponentScan(basePackages = "cz.muni.fi.cep")
public class App extends WebMvcConfigurerAdapter {

public static void main(String[] args) {
SpringApplication.run(App.class, args);
}

...
}

和Activiti配置:

@Configuration
public class ActivitiConfig {

@Bean
public ProcessEngine processEngine(ProcessEngineConfigurationImpl pec, ApplicationContext applicationContext) throws Exception {
ProcessEngineFactoryBean pe = new ProcessEngineFactoryBean();
pe.setProcessEngineConfiguration(pec);
pe.setApplicationContext(applicationContext);

return pe.getObject();
}

@Bean
public ProcessEngineConfigurationImpl getProcessEngineConfiguration(
DataSource dataSource,
PlatformTransactionManager transactionManager,
ApplicationContext context) {
SpringProcessEngineConfiguration pec = new SpringProcessEngineConfiguration();

pec.setDataSource(dataSource);
pec.setDatabaseSchemaUpdate("true");
pec.setJobExecutorActivate(true);
pec.setHistory("full");
pec.setMailServerPort(2025);
pec.setDatabaseType("mysql");

pec.setTransactionManager(transactionManager);
pec.setApplicationContext(context);

return pec;
}

@Bean
public RuntimeService getRuntimeService(ProcessEngine processEngine) {
return processEngine.getRuntimeService();
}
...
}

此外,也许上下文创建的顺序与此有关。

最佳答案

一切看起来都不错,我相信这可能是简单的事情,比如订阅服务没有被扫描(它属于 cz.muni.fi.cep 包吗?),或者 Spring 为订阅服务 bean 分配了另一个名称(即dbSubscriptionServicedBSubscriptionService 而不仅仅是 subscriptionService)。

尝试用 @Service("subscriptionService") 替换 DBSubscriptionService 类中的 @Service ,它应该可以工作。

关于java - 基于注解的Spring Activiti ProcessEngine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28000569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com