0
votes

This the error that I'm getting:

SEVERE: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usuarioControlador': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.blah.base.database.DAO.UsuarioDAO com.blah.base.controlador.UsuarioControlador.usuarioDAO; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'UsuarioDAO' defined in file [C:\Users\Owner\workspaceSpring.metadata.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\base\WEB-INF\classes\com\yavale\base\database\hibernetDAO\UsuarioHibernetDao.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=sessionFactory)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=sessionFactory)}

This is my UsuarioControlador (controller):

@Controller
@RequestMapping("/")
public class UsuarioControlador {

private UsuarioDAO usuarioDAO;
@Autowired 
public void setUsuarioDAO(UsuarioDAO usuarioDAO) {
    this.usuarioDAO = usuarioDAO;
}

@RequestMapping(method = RequestMethod.GET)
public String list(Model model) {
    List<Usuario> usuarios = usuarioDAO.listarUsuarios();
    model.addAttribute("usuarios", usuarios);

    return "index";
}
}

This is UsuarioDAO:

public interface UsuarioDAO {

void insertarUsuario(Usuario usuario);
void modificarUsuario(Usuario usuario);
List<Usuario> listarUsuarios();
Usuario buscarUsuario(String idUsuario);
void eliminarUsuario(Usuario usuario);

}

This is the class that implements UsuarioDAO:

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Service;

@Service(value="UsuarioDAO")
public class UsuarioHibernetDao extends HibernateDaoSupport implements UsuarioDAO{

@Autowired
public UsuarioHibernetDao(@Qualifier("mySessionFactory") SessionFactory 
        sessionFactory) {
    this.setSessionFactory(sessionFactory);
}


public void insertarUsuario(Usuario usuario) {
    this.getHibernateTemplate().save(usuario);
}

public void modificarUsuario(Usuario usuario) {
    this.getHibernateTemplate().update(usuario);
}

public List<Usuario> listarUsuarios() {
    return this.getHibernateTemplate().find("from Usuario");
}

public Usuario buscarUsuario(String idUsuario) {
    return this.getHibernateTemplate().load(Usuario.class, idUsuario);
}

public void eliminarUsuario(Usuario usuario) {
    this.getHibernateTemplate().delete(usuario);
}

}

This is my servlet-context.xml: https://dl.dropboxusercontent.com/u/31349296/servlet-context.xml

I'm new with spring so Im completely lost with this.

Edit: this is the complete stack trace: https://dl.dropboxusercontent.com/u/31349296/log.txt

Edit2:

enter image description here

1
Please post complete stack traceharrybvp
I have edited the questionkiduxa

1 Answers

1
votes

You are using the wrong identifier in the Qualifier annotation. The bean id is "mySessionFactory" but you have given "sessionFactory". Also, make sure content component scan is scanning the right packages.

Update:

The other error is probably related to the import of the hibernate session. You should be using org.hibernate.Session instead of org.hibernate.classic.Session