日期:2014-05-17  浏览次数:20663 次

ssh整合会话工厂获得
在applicationContext.xml文件中配置了事务管理器

<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>

对应的方法也加入了注解

public class EmployeeService  implements EmployeeServiceInter {
@Transactional
public void addEmployee(Employee e) {
// TODO Auto-generated method stub
     sessionFactory.getCurrentSession().save(e);

}


当我用这种方式执行的时候为什么系统会报异常
  怎么能方便的得到会话工厂呢?
public class LoginAction extends ActionSupport {
    private EmployeeServiceInter employeeServiceInter;
/**
 * @return
 */
public String execute() {

        employeeServiceInter.addEmployee(employee);

public void setEmployeeServiceInter(EmployeeServiceInter employeeServiceInter) {
this.employeeServiceInter = employeeServiceInter;
}

ssh java bean class string

------解决方案--------------------
employeeServiceInter应该是空,加了default-autowire="byName"会自动去appilication.xml中找employeeServiceInter这个bean,然后通过set方法为你注入
------解决方案--------------------
default-autowire="byName" 通过name自动装配。