我明明DAO有方法 ,Spring 也注入了, 页面老报500 显示Action中调用的底层方法为空 ... 求解? Spring.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- Dao -->
<bean id="StudentInfoDAO" class="com.Sy.Dao.StudentInfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="LoginInfoDAO" class="com.Sy.Dao.LoginInfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- Biz -->
<bean id="loginBiz" class="com.Sy.Biz.LoginBizImpl">
<property name="logDao">
<ref bean="LoginInfoDAO"/>
</property>
</bean>
<bean id="stubiz" class="com.Sy.Biz.StudentBizImpl">
<property name="stuDao">
<ref bean="StudentInfoDAO" />
</property>
</bean>
<!-- Action -->
<bean name="login" class="com.Sy.Action.LoginAction">
<property name="logbiz" ref="loginBiz"></property>
</bean>
<bean name="stu" class="com.Sy.Action.StuinfoAction">
<property name="stuBiz" ref="stubiz"></property>
</bean>
</beans>Action::public class LoginAction extends ActionSupport { private LoginBiz logbiz; public void setLogbiz(LoginBiz logbiz) {
this.logbiz = logbiz;
} private LoginInfo logInfo = new LoginInfo(); public LoginInfo getLogInfo() {
return logInfo;
} public void setLogInfo(LoginInfo logInfo) {
this.logInfo = logInfo;
} public String execute() { List list = logbiz.findByExample(logInfo); -显示此方法为空 if (list.size() > 0 && list != null) {
return SUCCESS; }
return ERROR;
}}
- BIZ 业务逻辑层
import java.util.List;import com.Sy.Dao.LoginDao;
import com.Sy.Entity.LoginInfo;public class LoginBizImpl implements LoginBiz { private LoginDao logDao; public void setLogDao(LoginDao logDao) {
logDao = logDao;
} public void save(LoginInfo transientInstance) {
logDao.save(transientInstance);
} public List findByExample(LoginInfo instance) {
return logDao.findByExample(instance); }
--DAO层
public List findByExample(LoginInfo instance) {
log.debug("finding LoginInfo instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- Dao -->
<bean id="StudentInfoDAO" class="com.Sy.Dao.StudentInfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="LoginInfoDAO" class="com.Sy.Dao.LoginInfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- Biz -->
<bean id="loginBiz" class="com.Sy.Biz.LoginBizImpl">
<property name="logDao">
<ref bean="LoginInfoDAO"/>
</property>
</bean>
<bean id="stubiz" class="com.Sy.Biz.StudentBizImpl">
<property name="stuDao">
<ref bean="StudentInfoDAO" />
</property>
</bean>
<!-- Action -->
<bean name="login" class="com.Sy.Action.LoginAction">
<property name="logbiz" ref="loginBiz"></property>
</bean>
<bean name="stu" class="com.Sy.Action.StuinfoAction">
<property name="stuBiz" ref="stubiz"></property>
</bean>
</beans>Action::public class LoginAction extends ActionSupport { private LoginBiz logbiz; public void setLogbiz(LoginBiz logbiz) {
this.logbiz = logbiz;
} private LoginInfo logInfo = new LoginInfo(); public LoginInfo getLogInfo() {
return logInfo;
} public void setLogInfo(LoginInfo logInfo) {
this.logInfo = logInfo;
} public String execute() { List list = logbiz.findByExample(logInfo); -显示此方法为空 if (list.size() > 0 && list != null) {
return SUCCESS; }
return ERROR;
}}
- BIZ 业务逻辑层
import java.util.List;import com.Sy.Dao.LoginDao;
import com.Sy.Entity.LoginInfo;public class LoginBizImpl implements LoginBiz { private LoginDao logDao; public void setLogDao(LoginDao logDao) {
logDao = logDao;
} public void save(LoginInfo transientInstance) {
logDao.save(transientInstance);
} public List findByExample(LoginInfo instance) {
return logDao.findByExample(instance); }
--DAO层
public List findByExample(LoginInfo instance) {
log.debug("finding LoginInfo instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
解决方案 »
- 关于hibernate的子查询
- spring2.0 aop 取HttpSession问题
- 大家J2EE这条路是怎么走过来的?有什么经验教训?
- 如何保存图片到MySQL数据库中
- struts 标签中 <html:radio>用法, 高分求救 急等....
- 在jb2006下怎么启动tomcat?
- java的优势所在?
- 关于webservice用soap调用怎么写
- 使用Spring调用Sybase的存储过程,如何取得结果集?
- 如何用poi设置单元格的宽度
- 什么样的工作能接触到java比较深层一点的技术啊
- Exception sending context initialized event to listener instance of class org.
你上面好几个都是这样
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>你这样写是不对的 这样你的DAO没有什么用 肯定是空了你在DAO层再定义一个DAOImp层应该可以了 ,就像你的业务实现层一样