如问题所述,在 groovy 资源中使用 grails 服务的最佳方式是什么?我目前正在使用此代码:
private RoleService roleService;
public RoleCommand() {
this.roleService = (RoleService) Holders.getGrailsApplication().getMainContext().getBean("roleService");
}
有一个更好的方法吗?
编辑/解决方案: 我使用 Spring Dependency Injection 解决了它(使用 @Component 注释类并使用 Application.groovy 文件中的 @ComponentScan Annotation 注册包)