AnsweredAssumed Answered

Own UserManagement -problem with using tx:annotation-driven

Question asked by udoderk on Apr 13, 2013
Latest reply on Apr 16, 2013 by jbarrez
Hi all,
i wish to realize user management with own tables in other database for user and user groups for activiti explorer using declarative approach for transactions with additional transaction mananger.
Into activiti explorer must be possible only change user email and password. But i have the problem with declarative approach for transactions :evil:  :evil:

if i use declarative approach for transactions (also turn on via <tx:annotation-driven transaction-manager="myTransactionManager"/> in spring configuration ) the Cannot convert value of type [$Proxy6 implementing org.activiti.engine.impl.interceptor.Session,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.driveit.CustomUserManager  exception will be thrown :shock:


Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy6 implementing org.activiti.engine.impl.interceptor.Session,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.driveit.CustomUserManager' for property 'customUserManager'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy6 implementing org.activiti.engine.impl.interceptor.Session,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.driveit.CustomUserManager] for property 'customUserManager': no matching editors or conversion strategy found
   at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485)
   at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516)
   at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1406)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1365)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
   … 51 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy6 implementing org.activiti.engine.impl.interceptor.Session,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.driveit.CustomUserManager] for property 'customUserManager': no matching editors or conversion strategy found
   at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241)
   at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)
   … 57 more
The my user manager is registered as bean in spring configuration (beacuse it is needed imho for @Transacitonal ).

If i comment out this tx:annotation-driven setting, the my user manager will be correctly  injected.  :!:

But the declarative transactional management is turned off :-((

What is wrong???

Thanks a lot for your help!!!

P.S The classes and configs

package com.driveit;

import java.util.List;

import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.UserQueryImpl;
import org.activiti.engine.impl.persistence.entity.IdentityInfoEntity;
import org.activiti.engine.impl.persistence.entity.UserEntity;
import org.activiti.engine.impl.persistence.entity.UserManager;
import org.springframework.transaction.annotation.Transactional;
public class CustomUserManager extends UserManager {

   @Override
   public User createNewUser(String userId) {
      // TODO Auto-generated method stub
      return super.createNewUser(userId);
   }
// other methods of "activiti"-UserManager
}

custom factory
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.interceptor.SessionFactory;


public class CustomUserManagerFactory implements SessionFactory {

   CustomUserManager customUserManager;

   public Class<?> getSessionType() {
      // original UserManager
      return org.activiti.engine.impl.persistence.entity.UserManager.class;
   }

   public void setCustomUserManager(CustomUserManager customUserManager) {
      this.customUserManager = customUserManager;
   }

   public Session openSession() {
      // Customized UserManger extended from
      // org.activiti.engine.impl.persistence.entity.UserManager
      return customUserManager;
   }

Spring configuration

….
   <bean id="dbProperties"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location" value="classpath:db.properties" />
      <!– Allow other PropertyPlaceholderConfigurer to run as well –>
      <property name="ignoreUnresolvablePlaceholders" value="true" />
   </bean>

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="${jdbc.driver}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
      <property name="defaultAutoCommit" value="false" />
   </bean>

   <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="${jdbc.driver}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
      <property name="defaultAutoCommit" value="false" />
   </bean>

   <bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" />
   </bean>

   <bean id="myTransactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="myDataSource" />
   </bean>

<!– <tx:annotation-driven transaction-manager="myTransactionManager"/> –>

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="true" />
      <property name="customFormTypes">
         <list>
            <bean class="org.activiti.explorer.form.UserFormType" />
         </list>
      </property>

      <property name="customSessionFactories">
         <list>
            <ref bean="myCustomUserManagerFactory" />
            <!– <bean class="com.driveit.CustomUserManagerFactory" /> <bean class="com.your.app.CUstomGroupManagerFactory"
               /> –>
         </list>
      </property>
   </bean>

   <bean id="myCustomUserManager" class="com.driveit.CustomUserManager">
   </bean>

   <bean id="myCustomUserManagerFactory" class="com.driveit.CustomUserManagerFactory">
      <property name="customUserManager" ref="myCustomUserManager" />
   </bean>
….

whole spring configuration :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">

   <!– This Spring config file is NOT used in Alfresco, as the Activiti engine
      is wired in a different way there –>

   <bean id="demoDataGenerator" class="org.activiti.explorer.demo.DemoDataGenerator"
      init-method="init">
      <property name="processEngine" ref="processEngine" />
      <property name="createDemoUsersAndGroups" value="true" />
      <property name="createDemoProcessDefinitions" value="true" />
      <property name="createDemoModels" value="true" />
   </bean>

   <bean id="dbProperties"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location" value="classpath:db.properties" />
      <!– Allow other PropertyPlaceholderConfigurer to run as well –>
      <property name="ignoreUnresolvablePlaceholders" value="true" />
   </bean>

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="${jdbc.driver}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
      <property name="defaultAutoCommit" value="false" />
   </bean>

   <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="${jdbc.driver}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
      <property name="defaultAutoCommit" value="false" />
   </bean>

   <bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" />
   </bean>

   <bean id="myTransactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="myDataSource" />
   </bean>

<!– <tx:annotation-driven transaction-manager="myTransactionManager"/> –>

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="true" />
      <property name="customFormTypes">
         <list>
            <bean class="org.activiti.explorer.form.UserFormType" />
         </list>
      </property>

      <property name="customSessionFactories">
         <list>
            <ref bean="myCustomUserManagerFactory" />
            <!– <bean class="com.driveit.CustomUserManagerFactory" /> <bean class="com.your.app.CUstomGroupManagerFactory"
               /> –>
         </list>
      </property>
   </bean>

   <bean id="myCustomUserManager" class="com.driveit.CustomUserManager">
   </bean>

   <bean id="myCustomUserManagerFactory" class="com.driveit.CustomUserManagerFactory">
      <property name="customUserManager" ref="myCustomUserManager" />
   </bean>



   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"
      destroy-method="destroy">
      <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="activitiLoginHandler" class="org.activiti.explorer.ui.login.DefaultLoginHandler">
      <property name="identityService" ref="identityService" />
   </bean>

</beans>

Outcomes