AnsweredAssumed Answered

Problem with autowiring services/ geting services from a spring bean

Question asked by mahdi1 on Apr 8, 2015
Latest reply on Apr 14, 2015 by mahdi1
i tried the to methods to call Activiti services but it think my bean cant detect services from activiti.cfg.xml
when i add the @autowired to the services it sayes that could not autowire services, and i tried also this one but thye same problem, i think that my bean cant retrive services
here is my activiti.cfg.xml:

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

   <tx:annotation-driven transaction-manager="transactionManager" />
   
   <bean id="dataSourceActiviti"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      <property name="url" value="jdbc:mysql://localhost:3306/activiti" />
      <property name="username" value="root" />
      <property name="password" value="admin" />
   </bean>

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

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSourceActiviti" />
      <property name="transactionManager" ref="ActivitiTransactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="false" />
      
      
   </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="formService" factory-bean="processEngine"
      factory-method="getFormService" />
   <bean id="identityService" factory-bean="processEngine"
      factory-method="getIdentityService" />
</beans>
and this is my java code
[java]
@Component
@ManagedBean
@ViewScoped
public class EmployeeRequestMB {
   public void testOnClickButton() {
      
      System.out.println("test bean on click" );
      
      ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "classpath*:activiti.cfg.xml");
      RepositoryService repositoryService = (RepositoryService) applicationContext
            .getBean("repositoryService");
      
      String deploymentId = repositoryService
            .createDeployment()
            .addClasspathResource(
                  "diagrams/MyProcess.bpmn")
            .deploy()
            .getId();
   }

}
[/java]

and this is the problem shown on console

 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'repositoryService' is defined 

Outcomes