服务Liferay中的java.lang.NoSuchMethodError

时间:2013-09-17 08:34:58

标签: tomcat service liferay

我创建了一个portlet,我生成了.jar服务并将其移至/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();
        }
}

谢谢!

2 个答案:

答案 0 :(得分:0)

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

  1. getActiveRole是类RuleLocalServiceImpl中的非静态方法,您在静态上下文中调用它,在我这里也是如此
  2. 假设上述问题不是问题,则方法声明和方法调用中可能会有Date的不同版本,即java.util.Datejava.sql.Date

答案 1 :(得分:0)

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

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