0

resources.groovy of my Grails project is growing, so I am thinking of splitting it in some logical files that will be easier to mantain. After reading some questions, blogs, i got to know about importBeans or loadBeans. This works well only when application is run using grails run-app. However we I create a war and deploy it on JBoss, the custom bean files are not accessible. Also tried below with no luck - mentioned here - Load spring beans from custom groovy files in grails app

grails.war.resources = { stagingDir, args ->
  copy(todir: "${stagingDir}/WEB-INF/classes/spring") {
     fileset(dir:"grails-app/conf/spring") {
        include(name: "datasourceDefinitions.groovy")
        exclude(name: "resources.groovy")        
      }
  }
}

I have added datasourceDefinitions.groovy in grails-app/conf/spring. Please help.

nshweta
  • 499
  • 2
  • 7
  • 19

1 Answers1

2

The problem is due to the Spring bean configuration files are moved into the folder "WEB-INF/classes/spring/"(make sure the file is packaged in the.war) inside the WAR file. As what I did was locate the resource path in resources.groovy.

def loadFromFile = { name ->
    importBeans("file:grails-app/conf/spring/"+name)
}

def loadFromWar = { name ->
    def resource = application.parentContext.getResource("WEB-INF/classes/spring/"+name)
    loadBeans(resource)
}
def loadResource = application.isWarDeployed() ? loadFromWar : loadFromFile

loadResource "datasourceDefinitions.groovy"
loadResource "anotherBean.groovy"