Assuming you have below service class in your grails service(grails-app/services) directory.
And we also have a groovy class under the src(src/groovy) directory and we wanted to inject MyService in this class like below.
Finally, we put our injection logic in resources.groovy(grails-app/conf/spring/resources.groovy)
class MyService {
def printSomething() {
println "Hello World!!!"
}
}
And we also have a groovy class under the src(src/groovy) directory and we wanted to inject MyService in this class like below.
class HelloWorld {
MyService myService
def printHelloWorld() {
myService.printSomething();
}
}
Finally, we put our injection logic in resources.groovy(grails-app/conf/spring/resources.groovy)
import package.HelloWorld
beans = {
helloWorld(HelloWorld) {
myService = ref("myService")
}
}
No comments:
Post a Comment