Grails 3.3.3 generate-all <domain class> Creates only the Service Interface

﹥>﹥吖頭↗ 提交于 2021-01-28 11:48:44

问题


In Grails 3.3.3, when I run generate-all for a domain class, a Service Interface is generates (versus the actual Service Class from Grails 2.x). I actually didn't notice it until I tried to add a method to my service.

The interface gets placed in the services folder where the service would live. I actually do like the interface but I still want the service and the default implementations. How can I have both an interface and implementation live in the services folder if the interface already has the name of the service? (Ex the interface gets named ClientService.groovy so the implementation would have the same name)

Here is an example of an interface that get's generated

package project

import grails.gorm.services.Service

@Service(Client)
interface ClientService {

    Client get(Serializable id)

    List<Client> list(Map args)

    Long count()

    void delete(Serializable id)

    Client save(Client client)

}

回答1:


How can I have both an interface and implementation live in the services folder if the interface already has the name of the service?

If you have an interface marked with @Service then you shouldn't have an implementation source file at all. GORM Data Services generates the implementation for you at compile time. If you want to write some of the code yourself then instead of an interface write an abstract class and annotate it with @Service. There is no reason for you to have an interface marked with @Service and then write a class that implements that interface.



来源:https://stackoverflow.com/questions/49326761/grails-3-3-3-generate-all-domain-class-creates-only-the-service-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!