Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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
Spring 钩子中自定义服务生成器中的会话工厂未实例化_Spring_Liferay_Liferay 6_Sessionfactory_Liferay Hook - Fatal编程技术网

Spring 钩子中自定义服务生成器中的会话工厂未实例化

Spring 钩子中自定义服务生成器中的会话工厂未实例化,spring,liferay,liferay-6,sessionfactory,liferay-hook,Spring,Liferay,Liferay 6,Sessionfactory,Liferay Hook,我正在尝试在liferay 6.1钩子中创建一个新实体来定制日历portlet。我使用服务构建器创建了一个引用Liferay 6.1文档()的新实体。构建服务是成功的。这是生成的portlet-spring.xml文件 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="

我正在尝试在liferay 6.1钩子中创建一个新实体来定制日历portlet。我使用服务构建器创建了一个引用Liferay 6.1文档()的新实体。构建服务是成功的。这是生成的portlet-spring.xml文件

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="test.service.CalTimeSlotsLocalService" class="test.service.impl.CalTimeSlotsLocalServiceImpl" />
    <bean id="test.service.CalTimeSlotsService" class="test.service.impl.CalTimeSlotsServiceImpl" />
    <bean id="test.service.persistence.CalTimeSlotsPersistence" class="test.service.persistence.CalTimeSlotsPersistenceImpl" parent="basePersistence" />
</beans>
当我试着调试这个问题时,我发现会话工厂没有实例化,并且总是空的。 我有什么遗漏吗?我怎样才能解决这个问题


谢谢。

您可以在
caltimeslotsiml
类中使用
getcaltimeslospersistence().findAll()
,请尝试这种方法

public List<String> getTimeValues() throws SystemException {
    List<String> timeValues = new ArrayList<String>();
    for (CalTimeSlots obj : getCalTimeSlotses(0, getCalTimeSlotsesCount())) {
        timeValues.add(obj.getTimeValue());
    }
    return timeValues;
}
public List getTimeValues()引发系统异常{
List timeValues=new ArrayList();
for(CalTimeSlots对象:getCalTimeSlotses(0,getCalTimeSlotsesCount())){
add(obj.getTimeValue());
}
返回时间值;
}

您不应该实例化
CalTimeSlotsPersistenceImpl
,而是让Spring来管理它。目前,您正在创建一个spring不知道的实例,因此不会将依赖项注入到实例中。服务生成器生成的持久性类不引用基本持久性类吗?就我在base-spring.xml中所见,BasePersistence类有一个会话工厂。因此,任何自定义持久性类都将引用基本持久性,通过调试,我发现基本持久性类创建了一个会话工厂。如果不使用spring托管实例,这并不意味着什么。您正在自己创建实例。。。无论您要对其进行多少配置(实际上,使用AspectJ和编译或加载时编织将使其工作),如果您创建自己的实例,spring将不会对这些实例进行任何处理。感谢您的快速响应:)我使用xxUtil类获取表中的所有行,它正常工作,没有异常。
09:41:03,749 ERROR [http-bio-8080-exec-4][BasePersistenceImpl:186] Caught unexpected exception java.lang.NullPointerException
09:41:03,782 ERROR [http-bio-8080-exec-4][IncludeTag:253] Current URL /web/guest/what-we-do?p_p_id=86&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&controlPanelCategory=portlet_86&_86_redirect=%2F&_86_struts_action=%2Fportlet_configuration%2Fedit_configuration&_86_returnToFullPageURL=%2F&_86_portletResource=8&_86_previewWidth=&tabs2=display-settings generates exception: null
09:41:03,787 ERROR [http-bio-8080-exec-4][IncludeTag:154] java.lang.NullPointerException
at com.liferay.portal.service.persistence.impl.BasePersistenceImpl.closeSession(BasePersistenceImpl.java:74)
at test.service.persistence.CalTimeSlotsPersistenceImpl.findAll(CalTimeSlotsPersistenceImpl.java:517)
at test.service.persistence.CalTimeSlotsPersistenceImpl.findAll(CalTimeSlotsPersistenceImpl.java:416)
at test.service.impl.CalTimeSlotsLocalServiceImpl.getTimeValues(CalTimeSlotsLocalServiceImpl.java:55)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
public List<String> getTimeValues() throws SystemException {
    List<String> timeValues = new ArrayList<String>();
    for (CalTimeSlots obj : getCalTimeSlotses(0, getCalTimeSlotsesCount())) {
        timeValues.add(obj.getTimeValue());
    }
    return timeValues;
}