Reputation: 1037
We have a fairly involved web application written using spring-mvc with a maven build system and would like to harness all the power of Grails for the front end. So the Grails app will essentially call into the spring-mvc app's service layer to access its business logic and data.
I need some guidance with my architectural approach to this integration at a high level. From my understanding, I will need to; - add my spring-mvc app as a compile dependency in my BuildConfig.groovy. - Expose the service layer objects as service beans in my conf/spring/resources.groovy and inject them into my controllers
Questions: My spring-mvc app has lots of dependencies of its own (which it obviously has to have) which are causing lots of dependency errors. Should I be setting "transitive=false" in my config and calling all of these in my Grails app? How should the datasource get configured? I guess I have to integrate the applicationContext of my spring-mvc app by calling it from my Grails applicationContext and hope it all bootstraps nicely?
Upvotes: 1
Views: 508
Reputation: 187529
So the Grails app will essentially call into the spring-mvc app's service layer to access its business logic and data
Can you be a bit more specific about which components of the Spring MVC you want to use from Grails, is it just the services and datasource?
I will need to add my spring-mvc app as a compile dependency in my BuildConfig.groovy
yes
Expose the service layer objects as service beans in my
conf/spring/resources.groovy
Although you could make the Spring beans known to your Grails app by defining them individually in resources.groovy
, this is unnecessary because you've already defined them in an Spring XML file (presumably) in the Spring MVC project.
Instead you can use the importBeans method of the BeanBuilder to import the Spring beans defined in this XML file into the Grails app. Once you've added the Spring MVC project as a dependency of your Grails app, the Spring XML file should be on your classpath, so all you need to do is add the following to resources.groovy
beans = {
importBeans('classpath:/path/to/file/applicationContext-services.xml')
}
How should the datasource get configured?
A Spring bean named dataSource
defines the datasource that a Grails app uses. In a standard Grails app, this bean is created based on the configuration in DataSource.groovy
. If your Spring MVC app defines a bean with this name, then this should be used instead after making the changes above. To be sure that Grails is using the datasource from your Spring MVC app rather than whatever is in DataSource.groovy
, I guess you could delete the contents of the latter.
Upvotes: 3