关于getHibernateTemplate()==null的疑惑!!

最近做了个ssh项目遇到一个奇怪问题:在strtus的action里用注入进去的service获取的getHibernateTemplate()始终为null,而service本身方法里一切正常。
//au可以正常获取
//AdmUser au = (AdmUser) yxth.load(AdmUser.class, new Long(1000));
try {//不知道为啥是null?
if (yxth.getHibernateTemplate() == null) {
System.out.println("46777");
}
;
} catch (Exception rt) {
}

load方法如下:
public AdmUser load(Class<AdmUser> class1, Long s) {
log.debug("load " + DaoUtil.getEntityName(class1)
+ " instance with id: " + s);
try {
return this.getHibernateTemplate().get(class1, s);
} catch (ObjectNotFoundException ex) {
log.error("Not such Object with id:" + s, ex);
return null;
} catch (RuntimeException re) {
log.error("load failed!", re);
throw re;
}
}

applicationContext.xml配置文件

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="yxth36actionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- <bean id="fuchanSF"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation" value="classpath:yxfuchan.cfg.xml">
</property>
</bean>-->
<!-- <bean id="fuchanactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="fuchanSF" />
</property>
</bean>-->
<tx:advice id="yxth36TxAdvice" transaction-manager="yxth36actionManager">
<tx:attributes>
<tx:method name="find*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
<!--
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception"
/>
-->
</tx:attributes>
</tx:advice>
<!-- <tx:advice id="fuchanTxAdvice" transaction-manager="fuchanactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>-->
<!-- <bean id="serviceAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="proxyTargetClass" value="true" />
<property name="beanNames">
<list>
<value>*Service</value>
</list>
</property>

<property name="interceptorNames">
<list>
<value>yxth36TxAdvice</value>
<value>fuchanTxAdvice</value>

</list>
</property>
</bean>-->
<aop:config proxy-target-class="true">
<aop:pointcut id="yxth36ServiceOperation" expression="execution(* uniora.thorp.service.*.*(..))" />
<!--
<aop:pointcut id="fuchanV6ServiceOperation" expression="execution(*
uniora.thorp.fuchan.*.*(..))" />
-->
<aop:advisor advice-ref="yxth36TxAdvice" pointcut-ref="yxth36ServiceOperation" />
<!--
<aop:advisor advice-ref="fuchanTxAdvice"
pointcut-ref="fuchanV6ServiceOperation" />
-->
</aop:config>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>

</bean>
<!--
<bean id="hibernateTemplate2"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory"> <ref local="fuchanSF" /> </property>

</bean>
-->

<bean id="yxth36Service" class="uniora.thorp.service.Yxth36Service">

<property name="hibernateTemplate" ref="hibernateTemplate" />

</bean>
<!--
<bean id="fuchanV6Service" class="uniora.thorp.db.FuchanV6Service">

<property name="hibernateTemplate" ref="hibernateTemplate2" /> </bean>
-->

貌似getHibernateTemplate只能在service类里用,此类继承HibernateDaoSupport。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值