Loading custom spring bean definitions in a domain-supported Mule 4 application and FileNotFoundException

Development of REST APIs and enterprise integration patterns in Mule has the advantage of being able to quickly implement commonly required functionality. Its set of drag-and-drop and quickly configurable connectors make the implementation faster

Image showing database connection configuration in Mule 4

when compared to writing boilerplate code

Image showing commmon boilerplate code for database connection establishment in Java

However when you need connections to be made to a certain not-so-popular external system (DBMS, message broker system etc.) which might be unsupported by Mule out of the box, you'd write spring beans with all essential configuration values and indicate to Mule to load them. A Mulesoft blog post detailing the procedure for a database connecion in Mule 3 use-case is here

With Mule 4, things changed.

Loading spring bean definitions was moved one step farther with the added requirement to declare the spring context oneself and then pointing to the file containing beans. You also need to export the file containing bean definitions as mentioned here. Make that count 'two' now!

Issue:

For my case, I needed to declare a bean definition for a database connection and automatic initialization. I found this doc to be more appropriate. I placed my bean definition file in src/main/resources of my app. However I kept receiving a 'File Not Found' error message related to bean definition, immediately on test-deployments.

I went through official Mule documentation, tried different suggestions received from co-workers to no luck. No matter how I renamed and relocated files (to src/main/mule), the error was always "File not found".

Cause:

On closer comparsion with a sample app from my senior colleague, I found the only difference to be that - they 'load Spring Context', 'declare Spring dependencies' etc. all in the main app code (the only app) they have while - the app I was working with has 'Spring context and related dependencies(Maven)' declared in a domain project. As Mule 4 explicitly errors out when same configs, dependencies are declared in both domain project and any of the child apps, I was forced to remove such 'Spring Context' etc. declarations from my app letting the domain project provide them at the start.

Resolution:

I moved the bean definition file too into src/main/resources of domain project and then the error is gone!

You can find the logs produced (using a sample app) and other descriptive details here at the accepted answer to my public question

links

social