Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将Liferay 7.x与Oracle 11g2外部数据库连接-NullPointerException_Java_Tomcat_Liferay_Liferay 7_Liferay 7.1 - Fatal编程技术网

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

Java 将Liferay 7.x与Oracle 11g2外部数据库连接-NullPointerException,java,tomcat,liferay,liferay-7,liferay-7.1,Java,Tomcat,Liferay,Liferay 7,Liferay 7.1,首先,我尝试了Liferay CE portal-7.1.0-GA1和Liferay portal 7.0 CE GA1。我会详细解释我的过程。My portal-ext.properties(Liferay主文件夹)看起来: 罐子: ext-spring.xml的代码 <?xml version="1.0"?> <beans default-destroy-method="destroy" default-init-method="afterPropertie

首先,我尝试了Liferay CE portal-7.1.0-GA1和Liferay portal 7.0 CE GA1。我会详细解释我的过程。My portal-ext.properties(Liferay主文件夹)看起来:

罐子:

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> 

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(); 
    

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

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


      您可以始终使用纯JDBC(例如,不使用服务生成器),或者。目前我只知道它是针对7.0的,不是针对7.1的(但我在这里可能错了)

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

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

      例如,在组件中:

      @Reference
      private volatile CountryLocalService countryLocalService;
      
      Liferay的源代码中到处都有这样的示例,例如:

      您的帖子中没有足够的信息供任何人回答。什么是
      com.service.service.CountryLocalServiceUtil
      ?这就是错误所在。这是你的课吗?如果是这样的话,发布源代码并指出哪一行抛出异常。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();如果您提供的信息是准确的,那么NPE的原因是
      getService()
      返回
      null
      。是的,我尝试了Antonio插件,在Oracle数据库中获得了Liferay表。之后,我使用了以下步骤:-或-相同的错误!我是Liferay的新手,你能提供代码吗(怎么做)?我在回答中给你举了一个例子。
      public static int getCountriesCount() {
          return getService().getCountriesCount(); 
      }
      
      CountryLocalService.java @Transactional(propagation = Propagation.SUPPORTS, 
                                              readOnly = true)
      public int getCountriesCount(); 
      
      @Reference
      private volatile CountryLocalService countryLocalService;