cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with autowiring services/ geting services from a spring bean

mahdi1
Champ in-the-making
Champ in-the-making
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 
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
Not sure what is going wrong here, this is just a standard spring context xml being loaded … you sure it's picking up the right xml file?

I do see you've got annotations on your EmployeeRequestBean (JSF?). How is that all set up?

mahdi1
Champ in-the-making
Champ in-the-making
I am using Spring MVC and JSF in my project, I coppied this Activiti/Spring configurations from the Book "Activiti in Action" and I got this problem.
now the problem is resolved by placing the following bean at the first of the xml configuration :
<code>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  <property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
</code>

and all services are working fine with using the @autowired