Is there a way that code from a different module can be used from another module (like a dependency)? So that we can prevent duplicate code for two modules.
You just need to add the other module’s jar file as a dependency in your module, you can get the group and artifact id from the other module’s pom file
I can already access the classes from the jar file, but it seems that they are not declared as beans and this causes injection of auto-wired dependencies to fail. In my core module, I can use the beans just fine, but when I add a new module that is dependent on my core module, it cannot use the services from the core module.
Do I have to declare the classes as beans again in my moduleApplicationContext.xml file? Or is there a way to import the xml definitions from the jar?
Did you declare the core module as a required module in the dependent module’s config.xml file?
Yes I have, but the error still persists. “org.openmrs.api.APIException: Service not found”
<require_modules> <require_module org.openmrs.module.chitscore></require_module> </require_modules>
You need to specify a version
I have specified the version. But now I get this error.
First of all I think you should never be referencing a dao bean from a controller, it’s bad practice. Can you share the class you are auto wiring into and your module’s application context file if you’re using xml configuration?
I don’t know why it’s still there. Anyway, I just removed it. Thank you. But a new error has come up.
Can you try
@Autowired along with
@Qualifier on fields rather than on a single method that has multiple autowired argument values that are resolved by type because I think this might be the issue.
Alright I’ll try that. But it makes me wonder why the error only comes out when I add the additional module?
Update: The autowire error is gone. But the previous error has shown again.
An Internal Error has Occurred org.openmrs.api.APIException Service not found: interface org.openmrs.module.chitscore.CHITSService
Does does the config.xml look like for the module that uses chitscore? It would also help to paste the entire stack trace at pastebin.com
You also need to be more detailed on the issue you are running into for instance where in the code you are running into problems, several other things can lead to class loading issues.
This problem has already been solved.