Bean属性'sessionFactory'不可写或具有无效的setter方法

时间:2016-04-22 05:06:26

标签: java spring hibernate

我有1个错误:

Invalid property 'sessionFactory' of bean class [com.aptech.mavenspringmvc.dao.StudentDAOImpl]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

enter image description here

enter image description here

文件DAO工具

@Repository
public class StudentDAOImpl implements StudentDAO{
    @Autowired
public SessionFactory session;

文件DAO

@Service
public class StudentServiceImpl implements StudentService{

//@Autowired
public StudentDAO studao;

public void setStudao(StudentDAO studao) {
    this.studao = studao;
}

public StudentDAO getStudao() {
    return studao;
}

文件控制器

@Controller
public class StudentController {
// @Autowired
private StudentService stuSer;

2 个答案:

答案 0 :(得分:1)

@Repository
public class StudentDAOImpl implements StudentDAO{

 @Autowired
 public SessionFactory sessionFactory;
 ....

 public void setSessionFactory(SessionFactory sessionFactory){
     this.sessionFactory = sessionFactory;
  }
}

答案 1 :(得分:0)

在XML配置中,您要设置 studDao bean的 sessionFactory 属性。

但该属性在您发布的代码中被命名为会话