日期:2014-05-18  浏览次数:20912 次

spring为什么注入不了对象
 Spring配置
<!-- sessionfactory配置 -->
     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="configLocation">
      <value>classpath:hibernate.cfg.xml</value>
      </property>
     </bean>
     
    <!-- txManager配置 -->
     <bean id="txManage" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory"></property>
     </bean>
     
     <!-- 定义事务通知 -->
     <tx:advice id="txAdvice" transaction-manager="txManage">
      <tx:attributes>
      <tx:method name="*" propagation="REQUIRED"/>
      </tx:attributes> 
     </tx:advice>
     
     <aop:config>
      <aop:pointcut expression="execution(* dao..*.*(..))" id="serverMethod"/>
      <aop:advisor advice-ref="txAdvice" pointcut-ref="serverMethod"/>
     </aop:config>
     
     
     
     <!-- dao层 -->
     <bean id="ClassesDaoImpl" class="dao.impl.ClassesDaoImpl">
      <property name="sessionFactory" ref="sessionFactory"></property>
     </bean>
     
     <bean id="StudentDaoImpl" class="dao.impl.StudentDaoImpl">
      <property name="sessionFactory" ref="sessionFactory"></property>
     </bean>



action代码

package web.action;

import java.util.List;

import bean.Student;

import com.opensymphony.xwork2.ActionSupport;

import dao.StudentDao;

public class StuAction extends ActionSupport {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private StudentDao studentDao;
private List<Student> stulist;



public List<Student> getStulist() {
return stulist;
}

public void setStulist(List<Student> stulist) {
this.stulist = stulist;
}

public StudentDao getStudentDao() {
return studentDao;
}

public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
}



public String getStus(){

try {
stulist = studentDao.getStu();
return SUCCESS;
} catch (Exception e) {
// TODO Auto-generated catch block