JBPM 5.4 LocalTaskService scope in Spring - spring

I am using JBPM 5.4.0.Final with Spring 3.0.6
I am using local task service.
What should be the scope of org.jbpm.task.service.local.LocalTaskService if it is declared as a spring bean ? Can it be a singleton ?
tasks-context.xml:
<bean id="internalTaskService" class="org.jbpm.task.service.TaskService">
<property name="systemEventListener" ref="systemEventListener" />
</bean>
<bean id="htTxManager" class="org.drools.container.spring.beans.persistence.HumanTaskSpringTransactionManager">
<constructor-arg ref="transactionManager" />
</bean>
<bean id="springTaskSessionFactory" class="org.jbpm.task.service.persistence.TaskSessionSpringFactoryImpl" init-method="initialize"
depends-on="internalTaskService">
<property name="entityManagerFactory" ref="jbpmEMF" />
<property name="transactionManager" ref="htTxManager" />
<property name="useJTA" value="true" />
<property name="taskService" ref="internalTaskService" />
</bean>
<bean id="taskService" class="org.jbpm.task.service.local.LocalTaskService" depends-on="springTaskSessionFactory">
<constructor-arg ref="internalTaskService"></constructor-arg>
</bean>

The question is, how many instances do you need. If you have just one client of that application you can just create it singleton, it shouldn't affect the behavior. Let us know if you have any troubles with it.
Cheers

Related

Loading Custom activiti.cfg.xml

I am learning activiti.
Where I created one java application in that I am using hibernate + Spring + activiti where we have activiti.cfg.xml.
I want to load only database details like datasource and hibernate properties programatically, other thing e.g asyncExecutorActivate, etc I want to do using activiti.cfg.xml.
e.g
Following need to set using Programatically
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="<set_Using_Program>" />
<property name="url" value="<set_Using_Program>" />
<property name="username" value="<set_Using_Program>" />
<property name="password" value="<set_Using_Program>" />
</bean>
This Information set using activiti.cgf.xml
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
</beans>
How to do?
You can simply inject your values from properties file and build your own engine based on them. such as data source. follow this tutorial
You can also build extensions on them see userguide
for Spring Boot you can configure process engine like this code. activitiproperties is a custom class that I write to get mail server parameters.
#Autowired
private SpringProcessEngineConfiguration springprocessengineconfiguration;
springprocessengineconfiguration.setMailServerHost(activitiproperties.getMailServerHost());
springprocessengineconfiguration.setMailServerPort(activitiproperties.getMailServerPort());
springprocessengineconfiguration.setMailServerUsername(activitiproperties.getMailServerUserName());
springprocessengineconfiguration.setMailServerPassword(activitiproperties.getMailServerPassword());
springprocessengineconfiguration.setMailServerDefaultFrom(activitiproperties.getMailServerDefaultFrom());
springprocessengineconfiguration.setMailServerUseSSL(activitiproperties.isMailServerUseSsl());
springprocessengineconfiguration.setMailServerUseTLS(activitiproperties.isMailServerUseTls());

JPA hibernate insertion not locking

We are using SpringFramework 3.2.12.RELEASE, Hibernate 4.1.6.FINAL against Oracle 11g.
We have a service managed by JPATransactionManager. The service accepts an id as primary key and creates a new entity with the id, saves it, makes an external call, then updates the entity. Under multi-thread testing with the same id, I am expecting all other threads are blocking after the first thread has done the insertion and making external call, however it is not the case. The service is annotated with #Transactional(propagation=Propagation.REQUIRES_NEW, readOnly=false), and the two save calls are made via JpaRepository. Below is my spring configuration.
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"></property>
<property name="generateDdl" value="false"></property>
<property name="database" value="ORACLE"></property>
</bean>
<bean id="abstractEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
abstract="true">
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>
<bean id="myEntityManagerFactory" parent="abstractEntityManagerFactory">
<property name="persistenceUnitName" value="my" />
<property name="dataSource" ref="myDataSource" />
<property name="PackagesToScan" value="test.schema" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="myEntityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<jpa:repositories base-package="test.dao"
entity-manager-factory-ref="myEntityManagerFactory"></jpa:repositories>
Appreciate comments and help!

How can i get a Spring managed SessionCustomizer into the EclipseLink Config

I'm working with eclipselink in a spring project. one necessary part of my configuration is a SessionCustomizer that configures my id-generator (Snowflake by twitter).
Is it possible to handle the creation of this customizer with spring so i can use dependency injection and use property-placeholders?
The only examples i found for Customizers always configure the class in the persistence xml.
Here is my config so far:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="platform.auth-service" />
<property name="jpaDialect" ref="jpaDialect" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaPropertyMap" ref="jPAPropertyProviderMap" />
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="generateDdl" value="${database.generateTables}" />
<property name="databasePlatform" value="${database.platform}" />
</bean>
<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
While the #Configurable Annotation from spring-aop (AspectJ integration) would have been a solution i decided to solve my problem with a static SequenceHolder class where i store the sequences with a SequenceInstaller bean.
Finally the SessionCustomizer installs the stored sequences in the persistencecontextfactory.
I had to configure a dependency between the factory and the installer because spring might have handled the factory before the installer otherwise.

Tomcat deploy my project twice

Tomcat deploy my project twice. is anybody faced and solved this issue?. This is spring project and I am using quartz scheduler. because of this problem quartz running twice.
Using Quartz-2.1.1 and Spring framework 3.1.1
The quartz configuration is as follows :
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail" />
<property name="startDelay" value="10000" />
<property name="repeatInterval" value="1000" />
</bean>
<bean id="sc" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property>
</bean>
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="staFromInQObj" />
<property name="targetMethod" value="processInQueueData" />
<property name="concurrent" value="false" />
</bean>
I think this is the correct answer for the problem.
Spring 3 MVC dispatcher xml and applicationContext xml
Double deployments can happen due to spring configs as well !

EJB 3.0 -> Spring -> JPA (JTA as transaction manager)

I am currently working on a project that includes EJB 3.0 (stateless SB), JPA (Hibernate as the provider), JTA as transaction manager. The app server is JBoss AS 7. Spring is used for integrating EJB and JPA.
All seems to be working fine, except if there is any exception that occurs in the EJB, then the persistence unit is closed by Spring. On the subsequent request, the persistence unit is again created, which becomes time consuming and also should not happen in the ideal situation.
Below are the configuration details
persistence.xml
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<class>com.test.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
spring-application-context.xml
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<jee:jndi-lookup id="dataSource" jndi-name="java:/datasources/test" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"></entry>
<entry key="hibernate.current_session_context_class" value="jta" />
<entry key="hibernate.connection.release_mode" value="auto" />
</map>
</property>
<property name="persistenceUnitPostProcessors">
<list>
<bean class="com.transaction.processor.JtaPersistenceUnitPostProcessor">
<property name="jtaMode" value="true"/>
<property name="jtaDataSource" ref="dataSource"/>
</bean>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:/TransactionManager"></property>
<property name="autodetectUserTransaction" value="false"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
The class JtaPersistenceUnitPostProcessor is responsible for setting the transaction-type as JTA and the datasource to jta-datasource.
Could anyone please provide any help on this.
Thanks in advance.
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:jboss/TransactionManager" />
<property name="userTransactionName" value="java:comp/UserTransaction" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
you didn't specify any error message . you can add these lines in your configuration file .
I see you use JTA transaction manager and use that only if you use distributed Transaction and use JNDI. JTA tran. manager listens TX happening through connection acquired from JNDI datasource. If you have datasource created in your code and is not a part of Web container but is limited inside app. container in your web server, JTA wont work.
If you want to implement Tx manager with in a single app. context go for JPA transaction manager which is very reliable.

Resources