0

我创建了一个 portlet,生成了.jarof 服务并将其移动到/tomcat/lib/ext. 然后我创建了一个使用相同 BD 的钩子。但是当我尝试在钩子中执行“DynamicQuery”时它不起作用,然后我尝试在 中创建一个新函数RuleLocalServiceImpl.java,再次生成.jar并将其移动到/tomcat/lib/ext. 但它不起作用,当我尝试执行时出现此错误:

java.lang.NoSuchMethodError: com.segmentationPortlet.service.RuleLocalServiceUtil.getActiveRule(Ljava/util/Date;)Ljava/util/List;

这是函数的解码代码:

public class RuleLocalServiceImpl extends RuleLocalServiceBaseImpl {
   /*
    * NOTE FOR DEVELOPERS:
    *
    * Never reference this interface directly. Always use {@link com.segmentationPortlet.service.RuleLocalServiceUtil} to access the rule local service.
    */
    public List<Rule> getActiveRule(Date lastLogin) throws SystemException {
        DynamicQuery dq_rules = DynamicQueryFactoryUtil.forClass(Rule.class, PortalClassLoaderUtil.getClassLoader())
            .add(PropertyFactoryUtil.forName("modifiedDate").ge(lastLogin))
            .add(PropertyFactoryUtil.forName("status").eq(true));

            List<Rule> listRules = RuleLocalServiceUtil.dynamicQuery(dq_rules);
            return listRules;
    }
}

我尝试停止 tomcat,删除 .jar 并再次创建,但不起作用。

这是钩子的代码:

package com.segmentationProjecthookLogin.hook;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.util.PortalUtil;
import com.segmentationPortlet.model.ConditionsRule;
import com.segmentationPortlet.model.Rule;
import com.segmentationPortlet.service.ConditionsRuleLocalServiceUtil;
import com.segmentationPortlet.service.RuleLocalServiceUtil;


public class LoginAction extends Action {

    private static boolean  isVelocityEngineStarted = false;
    public void run(HttpServletRequest req, HttpServletResponse res) {     
        System.out.println("Login");
        User user;
        try {
            user = PortalUtil.getUser(req);     
            Date lastLogin = user.getLastLoginDate();
            List<Rule> listRule = RuleLocalServiceUtil.getActiveRule(lastLogin);
            System.out.println("Size " + listRule.size());
        } catch (PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (com.liferay.portal.kernel.exception.SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (com.liferay.portal.kernel.exception.PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}

谢谢!

4

2 回答 2

0

谢谢!但我已经解决了这个问题。错误在于钩子使用了旧版本的 .jar。我把链接放在这里:

https://www.liferay.com/es/community/forums/-/message_boards/message/29010435

于 2013-09-25T08:01:57.737 回答
0

以下是可能导致错误的可能性,按概率顺序排列。

  1. getActiveRole是类中的非静态方法,RuleLocalServiceImpl您在静态上下文中调用它,在我中也是如此
  2. 假设上面没有问题,可能Dateie的版本不同,java.util.Date而且java.sql.Date在方法声明和方法调用中。
于 2013-09-19T05:16:01.020 回答