# Access to Spring Beans in Script Task

**URL:** <https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209>\
**Category:** Flowable Engine\
**Created:** [January 11, 2020, 8:22am UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209 "2020-01-11T08:22:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![monick](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@monick](https://forum.flowable.org/u/monick)\
**Post date:** [January 11, 2020, 8:22am UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/1 "2020-01-11T08:22:47Z")

</div>

Hi,

I’m using Flowable 6.4.2 and I can access spring beans in script task with Groovy.

But I cannot do so when using javascript for script task. Apparently the bean names are resolved to null values and the following error occurs when I write beanName.call() in my script task:

“org.mozilla.javascript.EcmaError: TypeError: Cannot call method “call” of null”

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [January 17, 2020, 10:34pm UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/2 "2020-01-17T22:34:12Z")

</div>

Which JDK are you using (the org.mozilla seems to be a different package than usual)?

Did you try accessing the variable through e.g. execution.getVariable(‘foo’)?

---

<div class="post-metadata">

**Author:** ![monick](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@monick](https://forum.flowable.org/u/monick)\
**Post date:** [January 18, 2020, 7:20am UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/3 "2020-01-18T07:20:49Z")

</div>

I’m using OpenJDK 8.

Yes, I can access variables via execution.getVariable(“var1”);

I guess the problem comes from javascript secure scripting. Because this problem doesn’t show up when I disable secure scripting and remove the dependency to flowable-secure-javascript.

But I can’t find out how I can tweak it in order to make the Spring beans accessible.

---

<div class="post-metadata">

**Author:** ![monick](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@monick](https://forum.flowable.org/u/monick)\
**Post date:** [January 22, 2020, 10:55am UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/4 "2020-01-22T10:55:28Z")

</div>

Hi again,

I spent some time reading the relevant codes. I made a PR regarding this issue [here](https://github.com/flowable/flowable-engine/pull/2140).

I augmented the SecureScriptScope with ProcessEngineConfiguration’s beans.

I would be happy to know any comments about it.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [January 22, 2020, 1:46pm UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/5 "2020-01-22T13:46:04Z")

</div>

Hey @monick,

I had a brief look at the PR and it looks quite promising. The only thing we need to see is whether we want to be more restrictive here, since exposing all Spring Beans doesn’t sound too secure. You could get ahold of the `ApplicationContext` and close it, which I assume is something that you don’t want happening.

---

<div class="post-metadata">

**Author:** ![monick](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@monick](https://forum.flowable.org/u/monick)\
**Post date:** [January 23, 2020, 7:58am UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/6 "2020-01-23T07:58:09Z")

</div>

Hi @filiphr,

Surely I don’t want to expose all the Spring application context.

I think the term “Spring Beans” is a bit misleading.

I actually intend to expose the Beans that are registered via `SpringProcessEngineConfiguration#setBeans` and are normally accessible in EL expressions as well.

Thanks

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [January 23, 2020, 8:06am UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/7 "2020-01-23T08:06:32Z")

</div>

> [@monick](#):
>
> Surely I don’t want to expose all the Spring application context.

I figured as much. The thing is that currently by default the `beans` in the `SpringProcessEngineConfiguration` is actually a `SpringBeanFactoryProxyMap` which wraps the `ApplicationContext`. I know that you are probably going to configure the beans with different values, but perhaps we need changes to some other place as well (or don’t wrap the application context in the configuration)

---

<div class="post-metadata">

**Author:** ![monick](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@monick](https://forum.flowable.org/u/monick)\
**Post date:** [January 25, 2020, 7:53am UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/8 "2020-01-25T07:53:35Z")

</div>

Thanks @filiphr for your explanation.

I think if we don’t wrap the `ApplicationContext` in the configuration, that could cause some backward compatibility issues. Because it is supposed to be accessible in the expressions.

So I made some changes [here](https://github.com/flowable/flowable-engine/pull/2140/commits/c56260240b8711c8624deedef7ef5593a1d8ddfa). Where we can configure to expose the beans to the secure script task or not.(which is disabled by default).

---

<div class="post-metadata">

**Author:** ![ainze](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@ainze](https://forum.flowable.org/u/ainze)\
**Post date:** [March 25, 2020, 10:02pm UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/9 "2020-03-25T22:02:13Z")

</div>

Hi, does 6.5.0 expose Spring beans now? I see your PR got merged

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [March 25, 2020, 10:18pm UTC](https://forum.flowable.org/t/access-to-spring-beans-in-script-task/5209/10 "2020-03-25T22:18:10Z")

</div>

The PR above is about exposing the beans to a secure script (which is different from regular scripting, see [https://flowable.com/open-source/docs/bpmn/ch18-Advanced/#secure-scripting](https://flowable.com/open-source/docs/bpmn/ch18-Advanced/#secure-scripting)).

In regular javascript/groovy script tasks, the beans should be available as-is.  
What kind of script / script language are you using?
