无法引用权限助手 class

Can't reference a permission helper class

Liferay Forums

中询问

我按照解释的步骤 here:

为我的问题实体创建了权限助手 class
package net.carlosduran.nomedes.web.internal.security.permission.resource;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import net.carlosduran.nomedes.db.model.Question;

@Component(immediate = true)
public class QuestionPermission {

    public static boolean contains(
            PermissionChecker permissionChecker, Question question, String actionId) throws PortalException {

        return _questionModelResourcePermission.contains(permissionChecker, question, actionId);
    }

    public static boolean contains(
            PermissionChecker permissionChecker, long entryId, String actionId) throws PortalException {

        return _questionModelResourcePermission.contains(permissionChecker, entryId, actionId);
    }

    @Reference(
            target = "(model.class.name=net.carlosduran.nomedes.db.model.Question)", 
            unbind = "-")
    protected void setEntryModelPermission(ModelResourcePermission<Question> modelResourcePermission) {

        _questionModelResourcePermission = modelResourcePermission;
    }

    private static ModelResourcePermission<Question> _questionModelResourcePermission;

}

在 MVCRenderCommand 中 class 我这样引用它:

@Reference
protected QuestionPermission _questionPermission;

如果我包含此参考,渲染 class 将不起作用(我已尝试使用不同的渲染 classes)。

在我删除它的那一刻,渲染 class 没有问题。

service.xml 文件的代码是这样的:

<?xml version="1.0"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.4.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_4_0.dtd">

<service-builder dependency-injector="ds" package-path="net.carlosduran.nomedes.db">
    <namespace>Nomedes</namespace>
    <entity name="Question" local-service="true" uuid="true">


        <!-- PK fields -->

        <column name="questionId" primary="true" type="long"></column>

        <!-- Group instance -->

        <column name="groupId" type="long"></column>

        <!-- Audit fields -->

        <column name="companyId" type="long"></column>
        <column name="userId" type="long"></column>
        <column name="userName" type="String"></column>
        <column name="createDate" type="Date"></column>
        <column name="modifiedDate" type="Date"></column>
        <column name="title" type="String"></column>
        <column name="summary" type="String"></column>
        <column name="description" type="String"></column>
        <column name="status" type="int" />
        <column name="statusByUserId" type="long" />
        <column name="statusByUserName" type="String" />
        <column name="statusDate" type="Date" />
        
        <finder name="GroupId" return-type="Collection">
            <finder-column name="groupId"></finder-column>
        </finder>
        <reference entity="Group" package-path="com.liferay.portal"></reference>
    </entity>
    <exceptions>
        <exception>QuestionValidation</exception>
    </exceptions>
</service-builder>

谁能告诉我怎么了?谢谢

问题是我错过了在 QuestionPermission class 中的组件注释中添加 service 属性。

service = QuestionPermission.class

添加后效果很好。它看起来像这样:

@Component(
    immediate = true,
    service = QuestionPermission.class
)