Spring里的bean配置如下:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/ssh"></property>
<property name="username" value="root"></property>
<property name="password" value="fxfly"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/test/Sshdemo.hbm.xml</value>
</list>
</property>
</bean>
<bean id="testDao" class="com.test.TestDaoImp">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
DaoIMP如下:
public class TestDaoImp extends HibernateDaoSupport implements TestDao {
public boolean checkUser(String user, String pass) {
// TODO Auto-generated method stub
String hql = "from Sshdemo s where s.SName='" + user
+ "' and s.SPass='" + pass + "'";
List lt = null;
try {
System.out.println(this.getHibernateTemplate());
lt = this.getHibernateTemplate().find(hql);
} catch (Exception e) {
// TODO: handle exception
}
System.out.println(lt);
if(lt.size()>0){
return true;
}
return false;
}
}
为什么这个this.getHibernateTemplate()=null;
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/ssh"></property>
<property name="username" value="root"></property>
<property name="password" value="fxfly"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/test/Sshdemo.hbm.xml</value>
</list>
</property>
</bean>
<bean id="testDao" class="com.test.TestDaoImp">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
DaoIMP如下:
public class TestDaoImp extends HibernateDaoSupport implements TestDao {
public boolean checkUser(String user, String pass) {
// TODO Auto-generated method stub
String hql = "from Sshdemo s where s.SName='" + user
+ "' and s.SPass='" + pass + "'";
List lt = null;
try {
System.out.println(this.getHibernateTemplate());
lt = this.getHibernateTemplate().find(hql);
} catch (Exception e) {
// TODO: handle exception
}
System.out.println(lt);
if(lt.size()>0){
return true;
}
return false;
}
}
为什么这个this.getHibernateTemplate()=null;
解决方案 »
- 基于tomcat写的一个下载的功能,ie正常,firefox不正常
- 请问各位高手,如何将j2ee加入Myeclipse
- jsp 死活联不上 sql server 2000,怎么回事呢?
- velocity转义语法问题.
- 急救:hibernate+hsql初学者问题
- 高手解决weblogic的配置 JDBC 连接缓冲池问题
- <html:option>问题
- jpa hibernate 数据库连接池之间的关系
- 请教 setAttributeNS 函数的使用
- Container-ManagedPersistence的EJB设定EJB Relationship的问题
- java net url 问题
- 在web服务器可以上传 但是在客户端却上传不了
<property name="sessionFactory" ref="sessionFactory" />
</bean>看你的配置有注入进来,应该是spring配置懒加载的问题,当你的使用的时候才加载对象,该例中执行find方法的时候才会注入sessionFactory对象