# Calling Temporal's ActivityStub from Spring-Boot Service which is not a Worfkflow class throwing error. #26

**URL:** <https://community.temporal.io/t/calling-temporals-activitystub-from-spring-boot-service-which-is-not-a-worfkflow-class-throwing-error-26/13067>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [August 5, 2024, 4:15am UTC](https://community.temporal.io/t/calling-temporals-activitystub-from-spring-boot-service-which-is-not-a-worfkflow-class-throwing-error-26/13067 "2024-08-05T04:15:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mainak\_sethi](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/mainak_sethi/32/5679_2.png) [@mainak\_sethi](https://community.temporal.io/u/mainak_sethi)\
**Post date:** [August 5, 2024, 4:15am UTC](https://community.temporal.io/t/calling-temporals-activitystub-from-spring-boot-service-which-is-not-a-worfkflow-class-throwing-error-26/13067/1 "2024-08-05T04:15:14Z")

</div>

### 

What are you really trying to do?

1. We have multiple activities written in Python code.
2. We are writing workflows in Java leveraging those activities through Spring Boot.
3. I created an abstraction PythonClient in Java exposing all Python activities to Java Workflows.
4. On spawning the spring boot services it is throwing ActivityStub cannot be spawned from a non-workflow class.

### Describe the bug

@WorkflowInterface  
public interface CallPythonActivityWorkflow {

```auto
@WorkflowMethod
public GreetingActvityResponse greetInSpanish(GreetingActvityRequest greetingActvityRequest);

```

}

@WorkflowImpl(taskQueues = “python-greeting-tasks”)  
public class CallPythonActivityWorkflowImpl implements CallPythonActivityWorkflow {

```auto
@Autowired
private static final Logger logger = LoggerFactory.getLogger(CallPythonActivityWorkflowImpl.class);

```

// This is not getting instantiated  
private final PythonClient pythonClient;

```auto
@Autowired
public CallPythonActivityWorkflowImpl(PythonClient pythonClient) {
    this.pythonClient = pythonClient;
}

@Override
public GreetingActvityResponse greetInSpanish(GreetingActvityRequest greetingActvityRequest) {
    return pythonClient.greetInSpanish(greetingActvityRequest);
}

```

}

[@service](https://github.com/service)  
public class PythonClient {

```auto
private final ActivityOptions spanishGreetingActivityOptions
        = ActivityOptions.newBuilder()
        .setStartToCloseTimeout(Duration.ofSeconds(10))
        // todo move to an enum in proto
        .setTaskQueue("python-greeting-tasks")
        .build();

private final ActivityStub spanishGreetingActivityStub;

public PythonClient() {
    this.spanishGreetingActivityStub = Workflow.newUntypedActivityStub(spanishGreetingActivityOptions);
}

public GreetingActvityResponse greetInSpanish(GreetingActvityRequest greetingActvityRequest) {
    return spanishGreetingActivityStub.execute("JavaSpanishGreetingActivity", GreetingActvityResponse.class, greetingActvityRequest);
}
}

```

```auto

``

logs:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pythonClient' defined in file [/PythonClient.class]: Failed to instantiate [com.job_framework.client.PythonClient]: Constructor threw exception
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1317) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1202) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962) ~[spring-context-6.1.5.jar:6.1.5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) ~[spring-context-6.1.5.jar:6.1.5]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.4.jar:3.2.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-3.2.4.jar:3.2.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) [spring-boot-3.2.4.jar:3.2.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) [spring-boot-3.2.4.jar:3.2.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) [spring-boot-3.2.4.jar:3.2.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-3.2.4.jar:3.2.4]
at com..job_framework.JobFrameworkApplication.main(JobFrameworkApplication.java:10) [classes/:?]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com..job_framework.client.PythonClient]: Constructor threw exception
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:221) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:88) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1311) ~[spring-beans-6.1.5.jar:6.1.5]
... 17 more
Caused by: java.lang.Error: Called from non workflow or workflow callback thread
at io.temporal.internal.sync.DeterministicRunnerImpl.currentThreadInternal(DeterministicRunnerImpl.java:130) ~[temporal-sdk-1.23.2.jar:?]
at io.temporal.internal.sync.WorkflowInternal.getRootWorkflowContext(WorkflowInternal.java:738) ~[temporal-sdk-1.23.2.jar:?]
at io.temporal.internal.sync.WorkflowInternal.getWorkflowOutboundInterceptor(WorkflowInternal.java:734) ~[temporal-sdk-1.23.2.jar:?]
at io.temporal.internal.sync.WorkflowInternal.newUntypedActivityStub(WorkflowInternal.java:378) ~[temporal-sdk-1.23.2.jar:?]
at io.temporal.workflow.Workflow.newUntypedActivityStub(Workflow.java:118) ~[temporal-sdk-1.23.2.jar:?]
at com.job_framework.client.PythonClient.(PythonClient.java:25) ~[classes/:?]
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:195) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:88) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1311) ~[spring-beans-6.1.5.jar:6.1.5]

* Reproduction:
Added patch to reproduce on below example repo.
Repo: https://github.com/temporalio/spring-boot-demo/tree/main

[0001-Added-reproduction-scenarios.patch](https://github.com/user-attachments/files/16488144/0001-Added-reproduction-scenarios.patch)

### Environment/Versions

* OS and processor: [e.g. M1 Mac, x86 Windows, Linux]
* Temporal Version: [e.g. 1.14.0?] and/or SDK version
* Are you using Docker or Kubernetes or building Temporal from source?

### Additional context|
```

---

<div class="post-metadata">

**Author:** ![mainak\_sethi](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/mainak_sethi/32/5679_2.png) [@mainak\_sethi](https://community.temporal.io/u/mainak_sethi)\
**Post date:** [August 10, 2024, 5:15am UTC](https://community.temporal.io/t/calling-temporals-activitystub-from-spring-boot-service-which-is-not-a-worfkflow-class-throwing-error-26/13067/2 "2024-08-10T05:15:50Z")

</div>

@antonio.perez @spikhalskiy Can you provide an alternative to above?

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [August 12, 2024, 12:26pm UTC](https://community.temporal.io/t/calling-temporals-activitystub-from-spring-boot-service-which-is-not-a-worfkflow-class-throwing-error-26/13067/3 "2024-08-12T12:26:42Z")

</div>

Hi @mainak_sethi

DI in temporal workflows is not allowed since it could break determinism.

There are several spring-boot examples here,

- [samples-java/springboot at main · temporalio/samples-java · GitHub](https://github.com/temporalio/samples-java/tree/main/springboot)
- [samples-java/springboot-basic at main · temporalio/samples-java · GitHub](https://github.com/temporalio/samples-java/tree/main/springboot-basic)

Let me know if they are useful to you

Antonio

---

<div class="post-metadata">

**Author:** ![mainak\_sethi](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/mainak_sethi/32/5679_2.png) [@mainak\_sethi](https://community.temporal.io/u/mainak_sethi)\
**Post date:** [August 15, 2024, 7:21am UTC](https://community.temporal.io/t/calling-temporals-activitystub-from-spring-boot-service-which-is-not-a-worfkflow-class-throwing-error-26/13067/4 "2024-08-15T07:21:38Z")

</div>

Thanks @antonio.perez for informing.
