请大家帮忙看看ssh配置,为什么dao无法注入呢?

报错信息:
java.lang.NullPointerException (dao为null,我打印测试过这个)
com.bankond.base.service.impl.GenericServiceImpl.save(GenericServiceImpl.java:61)
com.bankond.action.RegisterAction.execute(RegisterAction.java:54)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
。。。。
。。。。

[img]http://dl.iteye.com/upload/attachment/487994/34d41de7-41c7-3c05-972f-faddaf31afa9.jpg[/img]

[code="java"]public interface GenericDao {
public abstract T save(T paramT);

  public abstract T merge(T paramT);

  public abstract T get(PK paramPK);

  public abstract void remove(PK paramPK);

  public abstract void remove(T paramT);

  public abstract void evict(T paramT);

  public abstract List<T> getAll();

 // public abstract List<T> getAll(PagingBean paramPagingBean);

  //public abstract List<T> getAll(QueryFilter paramQueryFilter);

  public abstract List<T> findByHql(String paramString, Object[] paramArrayOfObject);

  //public abstract List<T> findByHql(String paramString, Object[] paramArrayOfObject, PagingBean paramPagingBean);

  public abstract List<T> findByHql(String paramString, Object[] paramArrayOfObject, int paramInt1, int paramInt2);

  public abstract void flush();

}

[/code]

[code="java"]public class GenericDaoImplextends
HibernateDaoSupport implements GenericDao {
protected Log logger = LogFactory.getLog(GenericDaoImpl.class);

protected JdbcTemplate jdbcTemplate;

protected Class persistType;

protected Map<String, String> querys = new HashMap();

public GenericDaoImpl(){}
public GenericDaoImpl(Class persistType) {
    this.persistType = persistType;
}

public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
}

public void setPersistType(Class persistType) {
    this.persistType = persistType;
}



public void evict(T entity) {
    getHibernateTemplate().evict(entity);
}

public List<T> findByHql(final String hql, final Object[] objs) {
    return (List) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session)
                throws HibernateException, SQLException {
            Query query = session.createQuery(hql);
            if (objs != null) {
                for (int i = 0; i < objs.length; ++i) {
                    query.setParameter(i, objs[i]);
                }
            }
            return query.list();
        }
    });
}

public List<T> findByHql(final String hql, final Object[] objs,
        final int firstResult, final int pageSize) {
    return (List) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session)
                throws HibernateException, SQLException {
            Query query = session.createQuery(hql);
            query.setFirstResult(firstResult).setMaxResults(pageSize);
            if (objs != null) {
                for (int i = 0; i < objs.length; ++i) {
                    query.setParameter(i, objs[i]);
                }
            }
            return query.list();
        }
    });

}

public List<T> findByHql(String hql) {
    return findByHql(hql, null);
}

public void flush() {
    getHibernateTemplate().flush();
    }

public T get(PK id) {
    return (T) getHibernateTemplate().get(this.persistType, id);
}

public List<T> getAll() {
    return (List) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session)
                throws HibernateException, SQLException {
            String hql = "from "
                    + GenericDaoImpl.this.persistType.getName();
            Query query = session.createQuery(hql);
            return query.list();
        }
    });
}

public T merge(T entity) {
    getHibernateTemplate().merge(entity);
return entity;
}

public void remove(PK id) {
    getHibernateTemplate().delete(get(id));
    }

public void remove(T entity) {
    getHibernateTemplate().delete(entity);
    }

public T save(T entity) {
    getHibernateTemplate().saveOrUpdate(entity);
    return entity;
}

}[/code]

[code="java"]public abstract interface GenericService {
public abstract T save(T paramT);

  public abstract T merge(T paramT);

  public abstract void evict(T paramT);

  public abstract T get(PK paramPK);

  public abstract List<T> getAll();

  //public abstract List<T> getAll(PagingBean paramPagingBean);

  //public abstract List<T> getAll(QueryFilter paramQueryFilter);

  public abstract void remove(PK paramPK);

  public abstract void remove(T paramT);

  public abstract void flush();

}[/code]

[code="java"]public class GenericServiceImpl
implements GenericService {

protected Log logger = LogFactory.getLog(GenericServiceImpl.class);

public GenericServiceImpl(){}

protected GenericDao<T, Serializable> dao = null;
public GenericServiceImpl(GenericDao dao) {
      this.dao = dao;
}

public void setDao(GenericDao dao) {
    this.dao = dao;
}

public void evict(T entity) {
    this.dao.evict(entity);

}

public void flush() {
    this.dao.flush();

}

public T get(PK id) {
    return this.dao.get(id);
}

public List<T> getAll() {
    return this.dao.getAll();
}

public T merge(T entity) {
    return this.dao.merge(entity);
}

public void remove(PK id) {
    this.dao.remove(id);
}

public void remove(T paramT) {
    // TODO 自动生成方法存根

}

public T save(T entity) {
    System.out.println("传进来的entity:"+entity+"<==>这里的dao是:"+this.dao);
    return this.dao.save(entity);
}

}[/code]

[code="java"]
public interface BaseService extends GenericService{
}
[/code]
[code="java"]public class BaseServiceImpl extends GenericServiceImpl implements BaseService{
public BaseServiceImpl(){}
public BaseServiceImpl(GenericDao dao) {
super(dao);
}
}[/code]

查看全部
lingzhiye
lingzhiye
2011/05/26 12:25
  • spring
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复