将Liferay 7.x与Oracle 11g2外部数据库连接 - NullPointerException

问题描述 投票:0回答:2

首先,我尝试使用Liferay CE门户-7.1.0-GA1和Liferay门户7.0 CE GA1。我将解释我的过程的细节。我的portal-ext.properties(Liferay HOME文件夹)看起来像:

jdbc.ext.driverClassName=oracle.jdbc.OracleDriver
jdbc.ext.url=jdbc:oracle:thin:@localhost:1521:db
jdbc.ext.username=xxx
jdbc.ext.password=xxx

JAR文件:

- ojdbc14.jar (\liferay-portal-7.0-ce-ga1\tomcat-8.0.32\lib)
- liferay-portal-oracledb-support-1.0 and liferay-portal-oracledb-support-1.0-SNAPSHOT (liferay-portal-7.0-ce-ga1\tomcat-8.0.32\webapps\ROOT\WEB-INF\lib)
- added ext-spring.xml (\modules\DemoService\DemoService-service\build\resources\main\META-INF\spring)

ext-spring.xml的代码

    <?xml version="1.0"?>
    <beans default-destroy-method="destroy" default-init-method="afterPropertiesSet" xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
       <!--bean class="com.liferay.portal.dao.jdbc.spring.DataSourceFactoryBean"
          id="liferayDataSourceFactory">
          <property name="propertyPrefix" value="jdbc.ext." />
          <property name="properties">
              <props>
                  <prop key="custom.jndi.name">extDataSource</prop>
              </props>
          </property>
          </bean-->
       <bean class="com.liferay.portal.dao.jdbc.spring.DataSourceFactoryBean"
          id="liferayDataSourceFactory">
          <property name="propertyPrefix" value="jdbc.ext." />
       </bean>
       <bean
          class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"
          id="liferayDataSource">
          <property name="targetDataSource" ref="liferayDataSourceFactory" />
       </bean>
       <alias alias="extDataSource" name="liferayDataSource" />
    </beans> 

得到这个错误:

    00:10:31,259 ERROR [http-nio-8080-exec-5][render_portlet_jsp:131] null
    java.lang.NullPointerException
    at com.service.service.CountryLocalServiceUtil.getCountriesCount(CountryLocalServiceUtil.java:207)
    at com.demo.portlet.DemoPortlet.doView(DemoPortlet.java:39)
    at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:302)
    at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:474)
    at javax.portlet.GenericPortlet.render(GenericPortlet.java:262)
    at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.render(MVCPortlet.java:294)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
    at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:57)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:105)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at com.liferay.portal.osgi.web.servlet.context.helper.internal.ServletContextHelperRegistrationImpl$PortletServletWrapper.service(ServletContextHelperRegistrationImpl.java:507)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
    at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
    at com.liferay.portal.osgi.web.servlet.context.helper.internal.ServletContextHelperRegistrationImpl$RestrictPortletServletRequestFilter.doFilter(ServletContextHelperRegistrationImpl.java:527)
    at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(FilterRegistration.java:121)
    at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:45)
    at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:71) 

Country是service.xml中的实体,在Gradle构建服务之后,生成CountryLocalServiceUtil。如果您使用Liferay 7,这是创建第一个应用程序的简单过程。

这是生成的类,我可以给出代码:

  • 从Portlet,我刚刚调用函数CountryLocalServiceUtil.getCountriesCount()
  • CountryLocalServiceUtil中的此函数是: public static int getCountriesCount() { return getService().getCountriesCount(); }
  • 公开声明是: CountryLocalService.java @Transactional(propagation = Propagation.SUPPORTS, readOnly = true) public int getCountriesCount();
java tomcat liferay liferay-7 liferay-7.1
2个回答
0
投票

你正在运行Liferay 7.x CE。请注意,Liferay Community Edition(CE)仅支持开源数据库,例如没有Oracle。有一个社区提供的附加组件,可以添加对Oracle和其他商业数据库的支持,但是您没有表明已经安装了它。

因此,您似乎从受支持的数据库运行Liferay,并尝试在“jdbc.ext”数据库中连接到Oracle。我希望这不起作用,因为它需要servicebuilder映射到Oracle,尽管它们不包含在CE中。

您始终可以使用纯JDBC(例如,无服务构建器)或try Antonio's plugin。目前我只知道它是7.0,而不是7.1(但我可能在这里错了)


0
投票

我几乎可以肯定你的问题不是数据库,但服务对象不可用,因为你的问题不是getCountriesCount(),而是getService()

作为一个实验,尽量不要使用* Util类,而是使用OSGi @Reference来获得所需的服务,这应该排除数据库的问题(至少在这个问题上)。如果您无法获得该服务,您可能会发现比在* Util类中抛出的NPE更好的故障排除信息。

例如,在您的组件中:

@Reference
private volatile CountryLocalService countryLocalService;

Liferay的来源遍布各种例子,例如:https://github.com/liferay/liferay-portal/blob/180d89ccaa80b86e68402c73a1483cd9e1817311/modules/apps/export-import/export-import-resources-importer/src/main/java/com/liferay/exportimport/resources/importer/internal/util/ImporterFactory.java

© www.soinside.com 2019 - 2024. All rights reserved.