What is the best way to work with services in grails

I just started a grails project and haven’t found how to work with services using dependency injections and interfaces.

As I have seen so far in the documentation when creating a service, this is just the groovy class, which can be automatically connected wherever I want.

But what if I want to have an interface for a service and implement one of its implementation, as it was in Java using spring?

for example, I want to have a service interface. let it be MyService.groovy it will have 1 doSmth () method and I will have 2 implementations - MyServiceImpl1.groovy and MyServiceImpl2.groovy

I have a quartz job doing something like this def myService myService.doSmth ()

Where should I put the groovy interface (folder)? Should I create a package for this in src / groovy? How to configure .groovy resources to connect "myService" to 1 service implementation?

Any thoughts appreciated

Thanks in advance!

+3
source share
2 answers

Launching grails create-service [name]is a convenient way to deploy a service, but it does not create an interface with the implementation as you are looking for.

I would suggest placing your interface and implementations in src/groovyand using resources.groovythem to connect (you can access the environment if you want to deploy another implementation in the environment).

" Spring DSL" 14.2 , resources.groovy. resources.xml, XML, Groovy DSL.

+12

grails create-service [name]

0

Source: https://habr.com/ru/post/1785152/


All Articles