Announcement Announcement Module
Collapse
No announcement yet.
NoClassDefFoundError: org/springframework/jdbc/core/RowMapper Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Im 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
    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...

    Comment


    • #3
      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.

      Comment


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

        Comment


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

          Comment


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

            Comment


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

              Comment


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

                Comment


                • #9
                  I`ve copied this jars:

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

                  Comment


                  • #10
                    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?

                    Comment


                    • #11
                      Its my first time with java. Ive choose spring mvc template proyect to create it. Have you got the jar names I must include to make it work?

                      Comment


                      • #12
                        Have a look at the reference docs for a list of what you probably need.

                        http://static.springsource.org/sprin...l/ch02s06.html

                        Comment


                        • #13
                          Hello pvera

                          C:\Users\Admin>java.exe -classpath C:\Desarrollo\spring\GECODIMO\ref\*
                          Exception in thread "main" java.lang.NoClassDefFoundError:
                          Avoid working with -classpath to reference many jars, sometimes is a hell work in this way through the console

                          I suggest you consider Ant since you are working directly with Jars

                          Comment


                          • #14
                            Dr_pompeii I`ve added the jars because I need to access a mysql database from my spring mvc project and the references to JdbcTemplate and RowMapper are in those jars. So I added them to my project references from the spring IDE. Is there any other way to include database access instead of adding the jar to the references?

                            Comment


                            • #15
                              You need to put all of the jars you need into the WEB-INF/lib folder of your application. This is your RUNTIME classpath.

                              Your COMPILE time classpath is different. This is what Eclipse uses to compile your app.

                              Ideally you would use Ant or Maven to copy the relevant jars into your WEB-INF/lib ready for deployment.

                              Comment

                              Working...
                              X