I have a grails service:
MyService { def sessionFactory void someMethod() { //... sessionFactory.currentSession.createSQLQuery(sql); //... } }
I want to call this service from a groovy script (located in src / groovy). Invoking with the grails command - grails trial test - script src \ groovy \ CallMyService.groovy.
SessionFactory is null when this method is called (it works fine when run as an integration test). But I would like to call it through a script. How can I inject sessionFactory into a service? I tried modifying RunScript.groovy, for example, for example:
def sessionFactory = appCtx.getBean("sessionFactory") def session = SessionFactoryUtils.getSession(sessionFactory, true) TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session))
but it did not help. Any help was appreciated.
source share