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