I have three maven projects:
- demo-api: Contains POJOs for function APIs i.e.
OutputPojo.class, InputPojo.class
- demo-packaged-function: Defines a single function
public OutputPojo apply(InputPojo) {...}
that depends on the 'demo-api' project. - demo-deployer: Uses spring-cloud-function-deployer to run the packaged function, also depends on the 'demo-api' project.
If I use simple types for the function signature (i.e. refactor to String apply(String input) {...}
then everything works fine. However, with the setup described above I get the following exception:
Exception in thread "main" java.lang.ClassCastException: class org.example.function.api.InputPojo cannot be cast to class org.example.function.api.InputPojo (org.example.function.api.InputPojo is in unnamed module of loader 'app'; org.example.function.api.InputPojo is in unnamed module of loader org.springframework.cloud.function.deployer.FunctionArchiveDeployer$1 @7fedfe27)
Which makes sense becaues the class InputPojo
is loaded by both class loaders. If I don't package the function as a fat jar, i get ClassNotFoundException
when trying to deploy the jar, and I can't remove the dependency on demo-api
from the deployer project as otherwise I cannot use the POJO classes when calling the function. How is this meant to work without simple argument types for the functions?
The documentation doesn't cover this, and while there are examples of packaged functions using POJOs, i cannot find any examples of them actually being called by the deployer - other than one is the unit tests which demos type conversion and converts the POJO to Message.