@Autowired is not working in Delegate Service in SpringBoot using ${executeService} as Delegate Expression


#1

Hi,
I am fairly new to Camunda. In my project I have used the springboot integration for camunda. I made the required configuration as stated in document.

In one of my process, I need to call one Java class and call another service which is autowired in the same class.

I was able to trigger the process but getting null from service reference.

Below is the code :
public class ExecuteChange implements JavaDelegate{

@Autowired
TestService service;
private final static Logger LOGGER = Logger.getLogger("Execute-Change");

@Override
public void execute(DelegateExecution arg0) throws Exception {
	LOGGER.info("Processing request by '" + arg0.getVariable("customerId") +":"+ arg0.getVariable("fileId")+ "'...");
	System.out.println(service.test());
}

}
image

So, please help to triage this issue, as I tried various things but nothing is working


#2

Can you please show me your project structure.


#3

Project Structure:

GemmaBPMApplication looks like:
package com.optum.dentaleiei.gemma.bpm;

import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableProcessApplication
public class GemmaBpmApplication {

public static void main(String[] args) {
	SpringApplication.run(GemmaBpmApplication.class, args);
}

}

My pom.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

com.uhg
parent
2.0.0

</parent>
<groupId>com.optum.dentaleiei</groupId>
<artifactId>Gemma-BPM</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Gemma-BPM</name>
<description>Gemma BPM project.</description>

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<java.version>1.8</java.version>
	<spring.boot.version>2.1.5.RELEASE</spring.boot.version>
</properties>

<dependencyManagement>
	<dependencies>
		<dependency>
			<!-- Import dependency management from Spring Boot -->
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-dependencies</artifactId>
			<version>${spring.boot.version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

<dependencies>
	<dependency>
      <groupId>org.camunda.bpm.springboot</groupId>
      <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
      <version>3.3.1</version>
    </dependency>
    <dependency>
	  <groupId>org.camunda.bpm.springboot</groupId>
	  <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
	  <version>3.3.1</version>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-jpa</artifactId>
	</dependency>
	  <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
    </dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<scope>runtime</scope>
	</dependency>
	<dependency>
		<groupId>commons-io</groupId>
		<artifactId>commons-io</artifactId>
		<version>2.6</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-databind</artifactId>
		<version>2.9.4</version>
	</dependency>
	<dependency>
		<groupId>org.apache.poi</groupId>
		<artifactId>poi</artifactId>
		<version>3.12</version>
	</dependency>
	<dependency>
		<groupId>org.apache.poi</groupId>
		<artifactId>poi-ooxml</artifactId>
		<version>3.12</version>
	</dependency>
	<dependency>
		<groupId>org.json</groupId>
		<artifactId>json</artifactId>
		<version>20090211</version>
	</dependency>
	<dependency>
		<groupId>org.projectlombok</groupId>
		<artifactId>lombok</artifactId>
		<version>1.18.6</version><!--$NO-MVN-MAN-VER$-->
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger2</artifactId>
		<version>2.6.1</version>
		<scope>compile</scope>
	</dependency>
	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger-ui</artifactId>
		<version>2.6.1</version>
		<scope>compile</scope>
	</dependency>
</dependencies>

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<version>2.0.5.RELEASE</version>
			<executions>
				<execution>
					<goals>
						<goal>repackage</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.6.1</version>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
			</configuration>
		</plugin>
	</plugins>
</build>

#4

Its fixed!

I just needed to annotate the class ExecuteChange with @Service to create its bean and voila.

@Service
public class ExecuteChange implements JavaDelegate