Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: NoClassDefFoundError: org/springframework/jdbc/core/RowMapper

  1. #1
    Join Date
    May 2011
    Posts
    10

    Default NoClassDefFoundError: org/springframework/jdbc/core/RowMapper

    I´m trying to create a simple CRUD application with SPRING MVC. The compilation is ok but on execution time I get the error:


    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.De faultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'usuariosController' defined in file [C:\springsource\tc-server-developer-2.1.1.RELEASE\spring-insight-instance\wtpwebapps\GECODIMO\WEB-INF\classes\com\unlam\gecodimo\UsuariosController. class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.unlam.gecodimo.UsuariosController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/core/RowMapper


    This is the class:

    package servicios;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.List;
    import javax.sql.DataSource;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.RowMapper;
    import entidades.UsuarioEntity;

    public class UsuariosService
    {
    private JdbcTemplate jdbcTemplate;

    public UsuariosService()
    {
    }

    public void setDataSource(DataSource dataSource)
    {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public List<UsuarioEntity> RecuperarTodos()
    {
    String sql = "SELECT * FROM Usuarios";
    return jdbcTemplate.query(sql, new UsuarioMapper());
    }

    private static final class UsuarioMapper implements RowMapper<UsuarioEntity>
    {
    public UsuarioEntity mapRow(ResultSet rs, int rowNum) throws SQLException
    {
    UsuarioEntity usuario = new UsuarioEntity();
    usuario.setActivo(rs.getBoolean("Activo"));
    usuario.setCambiarClave(rs.getBoolean("CambiarClav e"));
    usuario.setClave(rs.getString("Clave"));
    usuario.setFechaCreacion(rs.getDate("FechaCreacion "));
    usuario.setFechaModificacion(rs.getDate("FechaModi ficacion"));
    usuario.setId(rs.getInt("IdUsuario"));
    usuario.setNombreCompleto(rs.getString("NombreComp leto"));
    usuario.setUsuario(rs.getString("Usuario"));
    usuario.setUsuarioCreacionId(rs.getInt("IdUsuarioC reacion"));
    usuario.setUsuarioModificacionId(rs.getInt("IdUsua rioModificacion"));
    return usuario;
    }
    }

    }

    ANY IDEAS HOW TO SOLVE THE PROBLEM?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    Use [ code][/code ] tags when posting code/stacktraces/xml that way it remains readable !!!

    Add the jar to your runtime classpath instead of only your compile time classpath...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2011
    Posts
    10

    Default

    Sorry about code it was my first post. How can I add the jar to the classpath? i`ve tried copying dlls to ext directory and it doesn`t work.

    I`ve also tried to create a folder, copy jar, and add the to classpath and get the following error:
    Code:
    C:\Users\Admin>java.exe -classpath C:\Desarrollo\spring\GECODIMO\ref\*
    Exception in thread "main" java.lang.NoClassDefFoundError: C:\Desarrollo\spring\
    GECODIMO\ref\org/springframework/jdbc_3/0/5/RELEASE/jar
    Caused by: java.lang.ClassNotFoundException: C:\Desarrollo\spring\GECODIMO\ref\o
    rg.springframework.jdbc_3.0.5.RELEASE.jar
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: C:\Desarrollo\spring\GECODIMO\ref\org.springframe
    work.jdbc_3.0.5.RELEASE.jar.  Program will exit.

  4. #4
    Join Date
    Aug 2004
    Location
    UK
    Posts
    108

    Default

    You need to put the jar into the WEB-INF/lib folder of your web app.

  5. #5
    Join Date
    May 2011
    Posts
    10

    Default

    I need only to copy the jar to that folder or I need to register them in some way?

  6. #6
    Join Date
    Aug 2004
    Location
    UK
    Posts
    108

    Default

    You just need to copy the jar - no registration is required.

  7. #7
    Join Date
    May 2011
    Posts
    10

    Default

    I`ve copy them and I`m getting the same error.

  8. #8
    Join Date
    Aug 2004
    Location
    UK
    Posts
    108

    Default

    Which jars have you got in the WEB-INF/lib?

  9. #9
    Join Date
    May 2011
    Posts
    10

    Default

    I`ve copied this jars:

    commons-dbcp-1.2.2
    org.springframework.jdbc_3.0.5.RELEASE
    org.springframework.transaction_3.0.5.RELEASE

  10. #10
    Join Date
    Aug 2004
    Location
    UK
    Posts
    108

    Default

    Looks like you're missing some jars. You need the Spring core jar and the Spring web jars as a minimum.

    I presume you're using STS? If so, have you considered creating a Spring Template project that uses Maven and sets up things like his for you without you having to worry about copying jars around?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •