日期:2014-05-19  浏览次数:20610 次

this.getHibernateTemplate() 为null
<?xml version="1.0" encoding="UTF-8"?>
<beans 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-2.5.xsd">


<bean id="DataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url"
value="jdbc:sqlserver://192.168.0.25:1433;database=test">
</property>
<property name="username" value="sa"></property>
<property name="password" value="123"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="DataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>model/user.hbm.xml</value>
</list>
</property>
</bean>

<bean id="czyDao" class="dao.KZ_CZY" scope="singleton">
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean>

<bean id="czyService" class="service.KZ_CZY" scope="singleton">
<property name="DAO" ref="czyDao"/>
</bean>

<bean id="loginAction" class="com.action.LoginAction" scope="prototype">
<property name="service" ref="czyService"/>
</bean>

</beans>



------解决方案--------------------
我也遇到这样的问题。。。不过貌似不是jar能解决哦!


Java code

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Usr = ((Tbl_Sae_User_Dao) context.getBean("userDao")).buildList();

------解决方案--------------------
我上次也是这样,sprign管理的,而不能自己new,否则就注入不进来