Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8963503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:22:14+00:00 2026-06-15T16:22:14+00:00

I’m having problems using Spring’s autowiring capabilities in Activiti Explorer when calling a service’s

  • 0

I’m having problems using Spring’s autowiring capabilities in Activiti Explorer when calling a service’s method from within a task. The idea is to have the Service Task call one of the methods on a Spring @Service bean in order to persist data using an @Autowired JPARepository.

Problem is, after executing the service task, I’m getting a null pointer exception as a result of the @Autowired Repository in myService not being properly instantiated.

My question then, is how can I properly call a Spring bean from the Task Service?

The JavaDelegate method does not work with Spring, and I’ve tried going for an “Expression” approach, as suggested here to no avail.

Here’s the code for the Service Task run method, which is being run as:

activiti:expression="${testServiceTask.doSomething()}"

// the java class that’s being called

public class testServiceTask {

@Autowired
private TestServiceDummy serviceDummy; 

public void doSomething() {
    serviceDummy.run(); // NPE here, the serviceDummy is null when called
    }
    // Getters and Setters for the testServiceDummy omitted for brevity

    }

Here is my service’s:

public interface TestServiceDummy {

public void createUser();

}


@Service(value = "testServiceDummyImpl")
@Transactional(readOnly = true)
public class TestServiceDummyImpl implements TestServiceDummy {

    @Autowired
    private UserRepository userRepo;

@Override
public void createUser() {
    User u = new User();
        userRepo.save(u);
    }

    // Getters and Setters for userRepo omitted for brevity
}

The same thing works without problems when called from our webapp (calling the service as a @ManagedProperty works ok) so the embedded project’s config seems to be ok.

And here’s Activiti Explorer’s applicationContext file:

<?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:jpa="http://www.springframework.org/schema/data/jpa"
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/tx 
        http://www.springframework.org/schema/tx/spring-tx-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/data/jpa 
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/jdbc 
        http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
        http://www.springframework.org/schema/jee 
        http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">

<import resource="classpath*:/applicationContextCore.xml" />
<context:property-placeholder location="classpath*:jdbc.properties" />

<!-- Scan this classpath for annotated components that will be auto-registered 
    as Spring beans -->
<context:annotation-config /> <!-- this should take care of the @Autowiring issue -->

<!-- scan the embedded project's components -->
    <context:component-scan base-package="my.project.*" /> 

<jpa:repositories base-package="my.project.repositories*" />

<bean
    class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<!-- Automatically translate hibernate/jpa exceptions into Spring's generic 
    DataAccessException hierarchy for those classes annotated with Repository -->
<bean
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<bean id="testServiceDummy" class="edu.bedelias.services.TestServiceDummyImpl" />

<!-- JPA Entity Manager Factory -->
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
    <property name="packagesToScan">
        <list>
            <value>edu.bedelias.*</value>
        </list>
    </property>
    <property name="jpaProperties">
        <props>
            <!-- set HibernateJpaVendorAdapter's behavior: 'create' = build a new 
                DB on each run; 'update' = modify an existing database; 'create-drop' = 'create' 
                and also drops tables when Hibernate closes; 'validate' = makes no changes 
                to the database -->
            <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
        </props>
    </property>
</bean>

<bean id="hibernateJpaVendorAdapter"
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="true" />
    <property name="generateDdl" value="false" />
    <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClass}" />
    <property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
    <property name="user" value="${jdbc.user}" />
    <property name="password" value="${jdbc.password}" />
    <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
    <property name="maxStatements" value="${jdbc.maxStatements}" />
    <property name="minPoolSize" value="${jdbc.minPoolSize}" />
</bean>

<!-- Transaction Manager is defined -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    <property name="dataSource" ref="dataSource" />
</bean>

<!-- Hijack the current @Session scope annotation on each @Service and make 
    it last only for the duration of the thread -->
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
    <property name="scopes">
        <map>
            <entry key="session">
                <bean class="org.springframework.context.support.SimpleThreadScope" />
            </entry>
        </map>
    </property>
</bean>

<!-- Enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven />

<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="demoDataGenerator" class="org.activiti.explorer.demo.DemoDataGenerator">
    <property name="processEngine" ref="processEngine" />
</bean>

<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>
            <ref bean="userFormType" />
        </list>
    </property>
</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>

<!-- Include the UI-related wiring. This UI context will be used in the 
    alfresco activiti admin UI -->
<import resource="activiti-ui-context.xml" />

<!-- Custom form types -->
<bean id="userFormType" class="org.activiti.explorer.form.UserFormType" />

If anyone is curious, the URL of the project is here:
Google Code hosted project

Thanks in advance,

Gaston

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:22:21+00:00Added an answer on June 15, 2026 at 4:22 pm

    This ended up working:

    ClassPathXmlApplicationContext cpx = new ClassPathXmlApplicationContext("classpath:applicationContextActiviti.xml");
    TestServiceDummy = (TestServiceDummy) cpx.getBean("testServiceDummy");
    

    Where applicationContextActiviti is a custom appContext config file with the TestServiceDummy service declared. I use this within the JavaDelegate class that gets called by the task.

    Basically, from Activiti Explorer I did not have visibility over Spring Beans (unless you get your hands dirty that is) so what I did was to skip the @Autowired and use the old manual approach to beans, then load them from within the caller class.

    Just leaving this here in case it hopes any future time travelers 😛

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am using jsonparser to parse data and images obtained from json response. When
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.