2

I have a problem with beans in mule 4. There is an error when trying to invoke java:

Element 'springService' is not defined in the Mule Registry

Error occures in run time.

I have created configuration.xml and declared spring config:

<spring:config name="springConfig" doc:name="springConfig" files="beans.xml" />

Then created beans.xml in /src/main/resources:

<beans ...>
  <context:component-scan base-package="com.services" />
</beans>

com.services is an external service that has a class:

@Service
public class SpringService {
...
}

EDIT1: The way I am trying to invoke java method:

<java:invoke doc:name="Get data" doc:id="id" class="com.services.SpringService" method="#[getData(String)]" instance="springService">
          <java:args><![CDATA[#[{name: vars.name}]]]></java:args>
</java:invoke>

Stack trace:

Message : Element 'springService' is not defined in the Mule Registry

Element : test-flow/processors/2 @ test-service:test.xml:14 (Get Data)

Element DSL : <java:invoke doc:name="Get data" doc:id="id" class="com.services.SpringService" method="#[getData(String)]" instance="springService"> java:args#[{name: vars.name}]</java:args> </java:invoke> Error type : MULE:UNKNOWN

FlowStack : at test-flow(test-flow/processors/2 @ test-service:test.xml:14 (Get Data)) at get:\getData(name):test-api-config(get:\getData(name):test-api-config/processors/0 @ test-service:test-api.xml:125 (Get Data)) at test-api-main(test-api-main/processors/0 @ test-service:test-api.xml:15)

Mateusz
  • 61
  • 5
  • How are you trying to invoke the bean? Please add the XML configuration to the question. Also add the complete error, not just the description. – aled Feb 08 '21 at 20:06
  • @aled I have edited my post. Could you look at it? – Mateusz Feb 08 '21 at 20:49

1 Answers1

0

The documentation of the Java Module doesn't say it can invoke a Spring bean instance. The examples always mention using the new operation of the module to create instances.At the least if possiblle it is not documented how. Probably unsupported by the current version of the Java module.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Is there a way to use spring beans in Mule 4? – Mateusz Feb 09 '21 at 07:50
  • You can use spring beans for some connectors. For example to define a data source for the database connector. I don't know a way to invoke methods directly. – aled Feb 09 '21 at 13:41