错误liferay:MVC Portlet don'
Liferay的Ima Bigenner,我跟随一家Tutoriel,使用Maven将服务构建器连接到Liferay的外部数据库。 我添加我的外部数据库如下:
jdbc.ext.url=jdbc:postgresql://localhost:8085/MyDB2
jdbc.ext.username=postgres
jdbc.ext.password=myPassWord
然后创建我的服务构建器,该构建器构建良好
<?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="spring" package-path="ntlink.db">
<namespace>ntlink</namespace>
<entity name="Candidat" local-service="true" table="candidats" data-source="candidat">
<column name="id_candidat" type="int" primary="true"></column>
<column name="nom_candidat" type="String"></column>
<column name="prenom_candidat" type="String"></column>
<column name="email_candidat" type="String"></column>
<column name="motdepass_cnandidat" type="String"></column>
</entity>
</service-builder>
,然后现在我拥有我的API.Jar和Service.jar,其中两个在我的./m2文件夹中 然后我创建我的MVC portlet:
@SuppressWarnings("unused")
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.header-portlet-css=/css/main.css",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=Candidat",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + CandidatPortletKeys.CANDIDAT,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class CandidatPortlet extends MVCPortlet {
@Reference
private volatile CandidatLocalService candidatLocalService;
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws java.io.IOException, PortletException {
try {
System.out.println("hello");
System.out.println("values===>"+ candidatLocalService.getCandidat(1).getEmail_candidat());
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.doView(renderRequest, renderResponse);
}
}
用注释@Reference我的portlet不会出现在窗口小部件和gogo shell中,我发现了此错误
Config Props: (11 entries)
com.liferay.portlet.display-category<String> = category.sample
com.liferay.portlet.header-portlet-css<String> = /css/main.css
com.liferay.portlet.instanceable<String> = true
component.id<Long> = 9479
component.name<String> = candidat.portlet.CandidatPortlet
javax.portlet.display-name<String> = Candidat
javax.portlet.init-param.template-path<String> = /
javax.portlet.init-param.view-template<String> = /view.jsp
javax.portlet.name<String> = candidat_CandidatPortlet
javax.portlet.resource-bundle<String> = content.Language
javax.portlet.security-role-ref<String> = power-user,user
References: (total 1)
- candidatLocalService: ntlink.db.service.CandidatLocalService UNSATISFIED 1..1 dynamic
target=(*) scope=bundle
,因此当我删除注释@Reference或用@BeanReference替换时,我得到了这个错误。错误
java.lang.NullPointerException: null
at candidat.portlet.CandidatPortlet.doView(CandidatPortlet.java:59) ~[?:?]
at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:303) ~[portal-kernel.jar:?]
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:509) ~[portal-kernel.jar:?]
at javax.portlet.GenericPortlet.render(GenericPortlet.java:291) ~[portlet.jar:3.0.1]
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.render(MVCPortlet.java:309) ~[portal-kernel.jar:?]
at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:127) ~[portal-impl.jar:?]
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:58) ~[portal-impl.jar:?]
at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:124) ~[portal-impl.jar:?]
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71) ~[portal-kernel.jar:?]
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115) ~[portal-kernel.jar:?]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[servlet-api.jar:4.0.FR]
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153) ~[?:?]
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62) ~[?:?]
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120) ~[?:?]
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48) ~[?:?]
at com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:570) ~[portal-impl.jar:?]
at com.liferay.portlet.internal.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:660) ~[portal-impl.jar:?]
at com.liferay.portlet.internal.InvokerPortletImpl.render(InvokerPortletImpl.java:345) ~[portal-impl.jar:?]
at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.lambda$render$0(MonitoringInvokerPortlet.java:259) ~[?:?]
at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet._render(MonitoringInvokerPortlet.java:363) ~[?:?]
,所以我不知道我的问题在哪里,以及如何确保新数据库已连接到我的项目。 PS:我的Liferay版本是7.4.3
i m a bigenner at liferay , i followed a tutoriel to Connect Service Builder to External Database in Liferay using MAVEN .
i add my external database like follow:
jdbc.ext.url=jdbc:postgresql://localhost:8085/MyDB2
jdbc.ext.username=postgres
jdbc.ext.password=myPassWord
then I create my service builder which is building well
<?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="spring" package-path="ntlink.db">
<namespace>ntlink</namespace>
<entity name="Candidat" local-service="true" table="candidats" data-source="candidat">
<column name="id_candidat" type="int" primary="true"></column>
<column name="nom_candidat" type="String"></column>
<column name="prenom_candidat" type="String"></column>
<column name="email_candidat" type="String"></column>
<column name="motdepass_cnandidat" type="String"></column>
</entity>
</service-builder>
then now I have my API.jar and service.jar the two of them are in my ./m2 folder
then I create my MVC portlet :
@SuppressWarnings("unused")
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.header-portlet-css=/css/main.css",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=Candidat",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + CandidatPortletKeys.CANDIDAT,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class CandidatPortlet extends MVCPortlet {
@Reference
private volatile CandidatLocalService candidatLocalService;
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws java.io.IOException, PortletException {
try {
System.out.println("hello");
System.out.println("values===>"+ candidatLocalService.getCandidat(1).getEmail_candidat());
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.doView(renderRequest, renderResponse);
}
}
with the annotation @Reference my portlet don't show up in the Widgets and in the GOGO shell i found this error
Config Props: (11 entries)
com.liferay.portlet.display-category<String> = category.sample
com.liferay.portlet.header-portlet-css<String> = /css/main.css
com.liferay.portlet.instanceable<String> = true
component.id<Long> = 9479
component.name<String> = candidat.portlet.CandidatPortlet
javax.portlet.display-name<String> = Candidat
javax.portlet.init-param.template-path<String> = /
javax.portlet.init-param.view-template<String> = /view.jsp
javax.portlet.name<String> = candidat_CandidatPortlet
javax.portlet.resource-bundle<String> = content.Language
javax.portlet.security-role-ref<String> = power-user,user
References: (total 1)
- candidatLocalService: ntlink.db.service.CandidatLocalService UNSATISFIED 1..1 dynamic
target=(*) scope=bundle
so when i delete the annotation @Reference or when i replace it with @beanReference i got this error
java.lang.NullPointerException: null
at candidat.portlet.CandidatPortlet.doView(CandidatPortlet.java:59) ~[?:?]
at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:303) ~[portal-kernel.jar:?]
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:509) ~[portal-kernel.jar:?]
at javax.portlet.GenericPortlet.render(GenericPortlet.java:291) ~[portlet.jar:3.0.1]
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.render(MVCPortlet.java:309) ~[portal-kernel.jar:?]
at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:127) ~[portal-impl.jar:?]
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:58) ~[portal-impl.jar:?]
at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:124) ~[portal-impl.jar:?]
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71) ~[portal-kernel.jar:?]
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115) ~[portal-kernel.jar:?]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[servlet-api.jar:4.0.FR]
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153) ~[?:?]
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62) ~[?:?]
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120) ~[?:?]
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48) ~[?:?]
at com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:570) ~[portal-impl.jar:?]
at com.liferay.portlet.internal.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:660) ~[portal-impl.jar:?]
at com.liferay.portlet.internal.InvokerPortletImpl.render(InvokerPortletImpl.java:345) ~[portal-impl.jar:?]
at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.lambda$render$0(MonitoringInvokerPortlet.java:259) ~[?:?]
at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet._render(MonitoringInvokerPortlet.java:363) ~[?:?]
so I don't figure out where's my problem and how can I assure that the new database is connected to my project.
Ps: my Liferay version is 7.4.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将两个服务构建器罐(API和服务实现)部署到Liferay,以便在运行时可用于Portlet。在Compiltime,Maven在.m2文件夹中找到了它们(仅需要API),但是在运行时,Liferay不知道检查该位置 - 但事实并非如此。
正如您所说,您是Liferay的初学者:我将从Liferay的标准依赖注入(例如OSGI)(或“ DS”,正如声明性服务在Service.xml声明中调用),而不是将Spring添加到游戏。添加Spring 可能会使您的情况变得复杂。我强烈建议您先了解服务构建器,然后再增加更复杂的性能。
You will need to deploy your two service-builder jars (the API and the service implementation) to Liferay, so that they are available for the portlet at runtime. At compiletime, Maven finds them (it only needs the API) in your .m2 folder, but at runtime, Liferay doesn't know to check that location - and it doesn't.
As you say you're a beginner in Liferay: I'd start with services through Liferay's standard dependency injection, e.g. OSGi (or "ds", as declarative services are called in the service.xml declaration), instead of adding spring to the game. Adding spring might complicate your situation. I'd strongly recommend to understand service builder first, before adding more complexity.