Finder Util class 不是由 Liferay 7 Service Builder 生成的

Finder Util class not generated with Liferay 7 Service Builder

虽然我在 Liferay 6.2 中使用 Service Builder 没有问题,但在构建服务以生成我的第一个 Finder Util class 时,我在 Liferay 7 中遇到了一个阻塞问题。 当我发现这一点时,我什至决定从头开始一个项目,问题仍然存在。 即使使用官方文档,也无济于事。

有人可以帮助我吗?

这是我在 Eclipse Mars 中上次测试的完整描述:

  1. 创建一个新的 Liferay 工作区
  2. 创建一个新的 Liferay 项目模块服务生成器
  3. 在 service.xml
  4. 中创建一个 foo 对象
  5. 构建服务 (class 生成良好)
  6. 在 persistence.impl 包
  7. 中手动创建一个 FooFinderImpl class
  8. 构建服务
    FooFinder 界面生成良好但 FooFinderUtil class 未生成。
  9. 在 FooFinderImpl 中添加一些方法 class
  10. 构建服务
  11. 没什么新鲜事

谢谢你的帮助。

文森特

构建服务时,build.gradle 中有一些属性,因此如果您想生成 Util class 必须将 osgiModule 设置为 false。

buildService {
    apiDir = "../foo-api/src/main/java"
    osgiModule = false
    propsUtil = "com.liferay.docs.foo.service.util.PropsUtil"
}

否则,如果你想使用 osgi,你可以通过这种方式检索查找器

@Reference
private volatile FooFinder fooFinder;

@Reference(unbind = "-")
protected void setFooFinder(
        FooFinder fooFinder) {

    _fooFinder = fooFinder;
}

private FooFinder _fooFinder;

有关更多信息,请参阅 liferay-docs https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/finding-and-invoking-liferay-services

示例 github http://github.com/bruinen/liferay-services-example

来自https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/custom-sql

Note: In previous versions of Liferay Portal, your finder methods were accessible via -FinderUtil utility classes. Finder methods are now injected into your app’s local services, removing the need to call finder utilities.

您现在应该可以在服务层直接调用您的查找方法:fooFinder.findBy...