gpt4 book ai didi

java - 在 EXT 中添加自定义方法时出现问题

转载 作者:行者123 更新时间:2023-12-01 11:26:17 32 4
gpt4 key购买 nike

我在 EXT 中添加自定义方法时遇到了这个问题。这是我的代码,

public class MyBlogsEntryServiceImpl extends BlogsEntryServiceImpl{


protected static final String DISPLAY_STYLE_VIEWS = "views";
protected static final String DISPLAY_STYLE_AVATAR = "avatar";

public List<BlogsEntry> getCompanyEntriesByViews(
long companyId, Date displayDate, int status, int max)
throws PortalException, SystemException {

long blogsEntryClassNameId = ClassNameLocalServiceUtil.getClassNameId(BlogsEntry.class);

DynamicQuery blogsEntriesQuery = DynamicQueryFactoryUtil.forClass(BlogsEntry.class, "BlogsEntry")
.setProjection(ProjectionFactoryUtil.property("BlogsEntry.entryId"))
.add(PropertyFactoryUtil.forName("BlogsEntry.companyId").eq(companyId));

DynamicQuery mostViewedAssetsQuery = DynamicQueryFactoryUtil.forClass(AssetEntry.class, "AssetEntry")
.add(PropertyFactoryUtil.forName("AssetEntry.classPK").in(blogsEntriesQuery))
.add(PropertyFactoryUtil.forName("AssetEntry.classNameId").eq(blogsEntryClassNameId))
.addOrder(OrderFactoryUtil.desc("AssetEntry.viewCount"));

if (max > 0) {
mostViewedAssetsQuery.setLimit(0, max);
}

List<AssetEntry> assetEntries = AssetEntryLocalServiceUtil.dynamicQuery(mostViewedAssetsQuery);

List<BlogsEntry> blogsEntries = new ArrayList<BlogsEntry>(assetEntries.size());

for (AssetEntry asset : assetEntries) {
try {
BlogsEntry entry = blogsEntryLocalService.getBlogsEntry(asset.getClassPK());
if (BlogsEntryPermission.contains(getPermissionChecker(), entry, ActionKeys.VIEW)) {
blogsEntries.add(entry);
}
} catch (Exception e) {
_log.warn("Cannot find BlogsEntry with id " + asset.getClassPK());
}

}

return blogsEntries;
}
}

在上面的代码中,我遇到了 getCompanyEntriesByViews() 方法的异常,这是错误日志

05:22:29,156 INFO  [localhost-startStop-1][DialectDetector:71] Determine dialect for MySQL 5
05:22:29,281 INFO [localhost-startStop-1][DialectDetector:136] Found dialect org.hibernate.dialect.MySQLDialect
Starting Liferay Portal Community Edition 6.2 CE GA2 (Newton / Build 6201 / March 20, 2014)
05:22:52,093 INFO [localhost-startStop-1][BaseDB:484] Database does not support case sensitive queries
05:22:52,546 INFO [localhost-startStop-1][ServerDetector:119] Server supports hot deploy
05:22:52,546 INFO [localhost-startStop-1][PluginPackageUtil:1013] Reading plugin package for the root context
05:25:23,250 INFO [localhost-startStop-1][AutoDeployDir:139] Auto deploy scanner started for E:\liferay62-migration\liferay-portal-6.2-ce-ga2\deploy
05:25:23,828 ERROR [localhost-startStop-1][JSONWebServiceRegistrator:96] java.lang.IllegalArgumentException: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy153.getCompanyEntriesByViews(long, java.util.Date, int, int)
java.lang.IllegalArgumentException: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy153.getCompanyEntriesByViews(long, java.util.Date, int, int)
at com.liferay.portal.jsonwebservice.JSONWebServiceActionConfig.<init>(JSONWebServiceActionConfig.java:79)
at com.liferay.portal.jsonwebservice.JSONWebServiceActionsManagerImpl.registerJSONWebServiceAction(JSONWebServiceActionsManagerImpl.java:269)
at com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionsManagerUtil.registerJSONWebServiceAction(JSONWebServiceActionsManagerUtil.java:92)
at com.liferay.portal.jsonwebservice.JSONWebServiceRegistrator.registerJSONWebServiceAction(JSONWebServiceRegistrator.java:261)
at com.liferay.portal.jsonwebservice.JSONWebServiceRegistrator.onJSONWebServiceBean(JSONWebServiceRegistrator.java:195)
at com.liferay.portal.jsonwebservice.JSONWebServiceRegistrator.processBean(JSONWebServiceRegistrator.java:93)
at com.liferay.portal.jsonwebservice.JSONWebServiceRegistrator.processAllBeans(JSONWebServiceRegistrator.java:68)
at com.liferay.portal.jsonwebservice.JSONWebServiceActionsManagerImpl.registerServletContext(JSONWebServiceActionsManagerImpl.java:324)
at com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionsManagerUtil.registerServletContext(JSONWebServiceActionsManagerUtil.java:102)
at com.liferay.portal.events.GlobalStartupAction.run(GlobalStartupAction.java:317)
at com.liferay.portal.events.EventsProcessorImpl.processEvent(EventsProcessorImpl.java:108)
at com.liferay.portal.events.EventsProcessorImpl.process(EventsProcessorImpl.java:59)
at com.liferay.portal.events.EventsProcessorUtil.process(EventsProcessorUtil.java:32)
at com.liferay.portal.servlet.MainServlet.processGlobalStartupEvents(MainServlet.java:1038)
at com.liferay.portal.servlet.MainServlet.init(MainServlet.java:314)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy153.getCompanyEntriesByViews(long, java.util.Date, int, int)
at java.lang.Class.getMethod(Unknown Source)
at com.liferay.portal.jsonwebservice.JSONWebServiceActionConfig.<init>(JSONWebServiceActionConfig.java:73)
... 31 more

我有一些疑问。1. 我们可以在 EXT 中添加我们的自定义方法吗?2.如果是,那么上述问题的解决办法是什么。

请给我建议。

最佳答案

  1. 我们可以在 EXT 中添加自定义方法吗?

如果这意味着将方法添加到现有接口(interface):。您无法更改接口(interface) - API 必须保持稳定 - 考虑需要针对您的版本实现的插件的影响Liferay 界面与我的版本的 Liferay 界面。

  • 如果是,那么上述问题的解决方案是什么。
  • 尽管上面是“否”,我还是会回答这个问题,因为有一个非常简单甚至易于维护的解决方案:

    你只需用它自己的服务实现一个钩子(Hook),例如我的博客扩展。这可能只有一种方法,例如getCompanyEntriesByViews。这个方法的实现只是委托(delegate)给Liferay的BlogService。现在您有了一个可以使用、维护的钩子(Hook),并且不会破坏众所周知的 API。它与各种应用程序兼容,这就是您想要的。

    关于java - 在 EXT 中添加自定义方法时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30778625/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com