初学者,请帮忙说说为什么!
public class test {
DBSetDAO dbsetDAO;
public DBSetDAO getDbsetDAO() {
return dbsetDAO;
}
public void setDbsetDAO(DBSetDAO dbsetDAO) {
this.dbsetDAO = dbsetDAO;
}
public List getlist(String lujing) {
List list=dbsetDAO.findAll();//可以连接,没有问题
System.out.println("List:"+list.size());
}
}
//******连接数据库*********
public class DBSetDAO extends HibernateDaoSupport {
public DBSetDAO() {
}
protected void initDao() {
// do nothing
}
public List findAll() {
try {
return getHibernateTemplate().find("from user");
} catch (RuntimeException re) {
throw re;
}
}
}
//********applicationContext.xml******
<beans>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/epmis</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/ssh2/po/user.hbm.xml</value>
</list>
</property>
</bean>
<bean id="DBSetDAO" class="com.Hibernate.DBSetDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="test" name="test" class="com.Hibernate.test">
<property name="dbsetDAO">
<ref local="DBSetDAO" />
</property>
</bean>
</beans>
当我在别的类中使用
test mytest=new test ();
List list=mytest.getlist();
的时候报错!
不能查询出数据!
java.lang.NullPointerException
这是为什么?
我怎么修改一下!
public class test {
DBSetDAO dbsetDAO;
public DBSetDAO getDbsetDAO() {
return dbsetDAO;
}
public void setDbsetDAO(DBSetDAO dbsetDAO) {
this.dbsetDAO = dbsetDAO;
}
public List getlist(String lujing) {
List list=dbsetDAO.findAll();//可以连接,没有问题
System.out.println("List:"+list.size());
}
}
//******连接数据库*********
public class DBSetDAO extends HibernateDaoSupport {
public DBSetDAO() {
}
protected void initDao() {
// do nothing
}
public List findAll() {
try {
return getHibernateTemplate().find("from user");
} catch (RuntimeException re) {
throw re;
}
}
}
//********applicationContext.xml******
<beans>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/epmis</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/ssh2/po/user.hbm.xml</value>
</list>
</property>
</bean>
<bean id="DBSetDAO" class="com.Hibernate.DBSetDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="test" name="test" class="com.Hibernate.test">
<property name="dbsetDAO">
<ref local="DBSetDAO" />
</property>
</bean>
</beans>
当我在别的类中使用
test mytest=new test ();
List list=mytest.getlist();
的时候报错!
不能查询出数据!
java.lang.NullPointerException
这是为什么?
我怎么修改一下!