当前位置: 代码迷 >> J2EE >> java ssh有关问题
  详细解决方案

java ssh有关问题

热度:10   发布时间:2016-04-22 00:48:35.0
java ssh问题
最近使用struts2+spring3+hibernate3.3做练习测试,引入jpa生成Dao,最后用Action调用dao的时候显示null,请朋友们帮忙啊

代码如下:
applicationContext.xml:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="sshPU" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" /><bean
id="BsTAssessUpdeventDAO"
class="com.tanyao.ibm.daoImp.BsTAssessUpdeventDAO">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<bean id="BsTAssessEquipmentDAO"
class="com.tanyao.ibm.daoImp.BsTAssessEquipmentDAO">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<bean id="BsTAssessJichengshangDAO"
class="com.tanyao.ibm.daoImp.BsTAssessJichengshangDAO">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<bean id="BsTAssessActDAO"
class="com.tanyao.ibm.daoImp.BsTAssessActDAO">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
</beans>


Action:

public class Demo2Action extends ActionSupport implements ServletRequestAware{
private BsTAssessActDAO bstassessactdao;
private IBsTAssessActDAO ibstassessactdao;
private BsTAssessAct bstassessact;

public String demo1()
{
bstassessact = bstassessactdao.findById("402880ee3122d803013122d92c80002d");
System.out.println(ibstassessactdao+"输出的内容是月份:"+bstassessact.getMonth());
return SUCCESS;
}

public void setServletRequest(HttpServletRequest arg0) {
// TODO Auto-generated method stub

}

/**
* @return the bstassessactdao
*/
public BsTAssessActDAO getBstassessactdao() {
return bstassessactdao;
}

/**
* @param bstassessactdao the bstassessactdao to set
*/
public void setBstassessactdao(BsTAssessActDAO bstassessactdao) {
this.bstassessactdao = bstassessactdao;
}

/**
* @return the bstassessact
*/
public BsTAssessAct getBstassessact() {
return bstassessact;
}

/**
* @param bstassessact the bstassessact to set
*/
public void setBstassessact(BsTAssessAct bstassessact) {
this.bstassessact = bstassessact;
}

/**
* @return the ibstassessactdao
*/
public IBsTAssessActDAO getIbstassessactdao() {
return ibstassessactdao;
}

/**
* @param ibstassessactdao the ibstassessactdao to set
*/
public void setIbstassessactdao(IBsTAssessActDAO ibstassessactdao) {
this.ibstassessactdao = ibstassessactdao;
}
}

调用dao的时候后台不报bug,前台jsp界面直接显示NullPointException,代码指向action的dao,我调试debug发现dao为空,请朋友们帮忙看看,如何实现spring注入hibernate,然后调用到的~


------解决方案--------------------
最好给dao的代码看看,继承hibernatedaosupport类了吗?配置 里我没看到就hibernateTimplte的注入! 
例如:
public class BaseDAOImpl<T> extends HibernateDaoSupport implements BaseDAO<T> {

现在我倒认为你的配置文件有问题,有点乱,没仔细看,你再试试

------解决方案--------------------
我也没看你上面这么多代码,太多了,
大概出现这问题的原因
1.你的配置和你在action对应的dao不一样,(很可能是你配置首写的是大写,在action却是小写),
  相关解决方案