Hi,
I'm currently in the process of building a CRUD tool for an existing Spring-based application. The application is being included in the Grails app as a JAR library which seems to work fine.
To make use of the library's own spring context, I used to load it through:
def ctx = new ClassPathXmlApplicationContext( 'classpath:/applicationContextName.xml')
in my service. Unfortunately the context builds its own datasource (the library's default) which is no good, as I need to use the dataSource defined in Grails.
So, my solution was to just include the library's spring configuration with the Grails context by adding an import to the grails-app\conf\spring\resources.xml file.
This seems to work (in so much as all beans are loaded into the same context and I can now autowire the beans straight in to my service classes by using def variableName
.
Unfortunately, the dataSource defined in the library's spring config is overloading the dataSource defined in my Grails DataSource.groovy file!
Is there any way I can tell Grails to load the libary's spring configuration first, so that it then gets overridden by the rest of Grails config (and thus using Grails' DataSource)?
Thanks for your help,
James
...
As a tenporary measure, I've removed the dataSource entry in the dependancy's spring config file and its beans have been injected the dataSource created by the Grails config - this isn't ideal though, as I've had to make a 'special' build of the dependancy jar.