Announcement Announcement Module
Collapse
No announcement yet.
iBatis, JPetStore sample does not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • iBatis, JPetStore sample does not work

    Hello,
    I downloaded the JPetStore sample from
    https://src.springframework.org/svn/...ples.jpetstore

    Followed its readme.txt to build the package. The original pom does not work and I made minimal changes. I do need to include slf4j-simple-1.5.2.jar into the web-inf\lib directory. otherwise, it's the same.
    <version>1.0.0</version>
    <properties>
    <spring.version>3.0.2.RELEASE</spring.version>

    After deploying onto tomcat, I got an error of ClassNotFound. I do see the spring-orm-3.0.2.RELEASE.jar under the web-inf\lib directory with the class defined inside the jar.


    Thanks.
    Denis

    P.S. details of the error

    1734 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.CannotLoadBeanCl assException: Error loading class [org.springframework.samples.jpetstore.dao.ibatis.S qlMapAccountDao] for bean with name 'accountDao' defined in ServletContext resource [/WEB-INF/dataAccessC
    ontext-local.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: SqlMapClientDaoSupport
    at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1226)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.predictBeanType(Abstrac tAutowire
    CapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :1292)
    at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :858)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListable
    BeanFactory.java:545)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplic
    ationContext.java:872)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:423)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 47)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3972)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4467)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployWAR(H ostConfig.java:905)
    at org.apache.catalina.startup.HostConfig.deployWARs( HostConfig.java:740)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:500)
    at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1277)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:321)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:519)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:581)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:414)
    Caused by: java.lang.NoClassDefFoundError: SqlMapClientDaoSupport
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :620)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:124)
    at org.apache.catalina.loader.WebappClassLoader.findC lassInternal(WebappClassLoader.java:2527)
    at org.apache.catalina.loader.WebappClassLoader.findC lass(WebappClassLoader.java:1010)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1483)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1361)
    at org.springframework.util.ClassUtils.forName(ClassU tils.java:258)
    at org.springframework.beans.factory.support.Abstract BeanDefinition.resolveBeanClass(AbstractBeanDefini tion.java
    :408)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doResolveBeanClass(AbstractBeanFactory .java:124
    4)
    at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1215)

    ... 33 more
    Caused by: java.lang.ClassNotFoundException: SqlMapClientDaoSupport
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1516)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1361)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    ... 44 more
    Jun 10, 2010 3:16:06 PM org.apache.catalina.core.StandardContext start
    SEVERE: Error listenerStart
    Jun 10, 2010 3:16:06 PM org.apache.catalina.core.StandardContext start
    SEVERE: Context [/jpetstore] startup failed due to previous errors

  • #2
    I get the following problem using Sts 2.3.3.M2. Another strange thing is that I get 203 errors, all of them in jsp's and xml files. I don't think it is related, but it would be nice if when jPetstore is fixed, they also update the readme.txt to explain why these 203 errors appear. Also, the server.sh script does not have a first line that declares what scripting language to use, so when I run it on the command line it complains, "server.sh: command not found". So, I run its contents manually: "mvn -e -Ddb.file=./jpetstore exec:java"
    Code:
    INFO: Starting Servlet Engine: SpringSource tc Server runtime/6.0.25.A
    ASPECTJ: aspectj.overweaving=true: overweaving switched ON
    Jul 26, 2010 7:46:45 AM org.apache.catalina.core.StandardContext listenerStart
    SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
    java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3915)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
    It's nice that Spring can fix/improve the Samples, and all we need to do is a Subversion "update". Still, I would feel warmer and fuzzier if Spring would do their final test of a sample, prior to committing to Subversion, with a brand new, never before used instance of STS and an empty maven local repository. I suspect they do not do this, and it is accounting for these types of problems on our end.
    Last edited by RobertGloverJr; Jul 26th, 2010, 03:02 PM.

    Comment


    • #3
      The problems I am experiencing seem to have their genesis in these errors which occur when I do (using m2Eclipse in STS) a "Maven Package":
      Code:
      [ERROR] BUILD ERROR
      [INFO] ------------------------------------------------------------------------
      [INFO] Failed to resolve artifact.
      
      Missing:
      ----------
      1) org.springframework:spring-webmvc:jar:3.0.0.BUILD-SNAPSHOT
      
        Try downloading the file manually from the project website.
      
        Then, install it using the command: 
            mvn install:install-file -DgroupId=org.springframework -DartifactId=spring-webmvc -Dversion=3.0.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
      
        Alternatively, if you host your own repository you can deploy the file there: 
            mvn deploy:deploy-file -DgroupId=org.springframework -DartifactId=spring-webmvc -Dversion=3.0.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
      
        Path to dependency: 
        	1) org.springframework.samples:org.springframework.samples.jpetstore:war:1.0.0-SNAPSHOT
        	2) org.springframework:spring-webmvc:jar:3.0.0.BUILD-SNAPSHOT
      
      2) org.springframework:spring-orm:jar:3.0.0.BUILD-SNAPSHOT
      
        Try downloading the file manually from the project website.
      
        Then, install it using the command: 
            mvn install:install-file -DgroupId=org.springframework -DartifactId=spring-orm -Dversion=3.0.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
      
        Alternatively, if you host your own repository you can deploy the file there: 
            mvn deploy:deploy-file -DgroupId=org.springframework -DartifactId=spring-orm -Dversion=3.0.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
      
        Path to dependency: 
        	1) org.springframework.samples:org.springframework.samples.jpetstore:war:1.0.0-SNAPSHOT
        	2) org.springframework:spring-orm:jar:3.0.0.BUILD-SNAPSHOT
      
      3) org.springframework:spring-context-support:jar:3.0.0.BUILD-SNAPSHOT
      
        Try downloading the file manually from the project website.
      
        Then, install it using the command: 
            mvn install:install-file -DgroupId=org.springframework -DartifactId=spring-context-support -Dversion=3.0.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
      
        Alternatively, if you host your own repository you can deploy the file there: 
            mvn deploy:deploy-file -DgroupId=org.springframework -DartifactId=spring-context-support -Dversion=3.0.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
      
        Path to dependency: 
        	1) org.springframework.samples:org.springframework.samples.jpetstore:war:1.0.0-SNAPSHOT
        	2) org.springframework:spring-context-support:jar:3.0.0.BUILD-SNAPSHOT
      
      ----------
      3 required artifacts are missing.
      To be continued tomorrow ....
      Oh, wait. Here's a totally unrelated question before I leave for work. I installed all the Spring 3.x samples, including petstore-groovy. The readme for petstore-groovy say to build it via "ant war" from a terminal window, which I did. But there are no instructions on how to use STS with petstore-groovy. I can't even find a Spring forum on the subject of groovy. And when I search the Spring forums for "petstore-groovy" there are no hits. Until now :-)
      Last edited by RobertGloverJr; Jul 27th, 2010, 10:41 PM.

      Comment


      • #4
        The solution to the problem is to change the "spring-version" property in the properties section of jpetstore's pom.xml.
        Before the fix:
        Code:
        <properties>
        		<spring.version>3.0.0.BUILD-SNAPSHOT</spring.version>
        		...snip...
        </properties>
        After the fix:
        Code:
        <properties>
        		<spring.version>3.0.3.RELEASE</spring.version>
        		...snip...
        </properties>
        To get the server.sh script to run (to start the hsqldb database), I did all of the following. Don't know if all were necessary, just know the server.sh script did actually work after doing the following:
        1) Used the directions at http://en.wikipedia.org/wiki/Shebang_%28Unix%29 to add the 1st line shown in the server.sh script below as shipped, server.sh only has 2 lines:
        Code:
        #!/bin/sh
        cd `dirname $0`
        mvn -e -Ddb.file=./jpetstore exec:java
        2) At a terminal window:
        Code:
        cd Documents/rdg/spring3Samples/spring-samples/jpetstore/trunk/org.springframework.samples.jpetstore/db/hsqldb
        
        new-host:hsqldb rdg$ chmod 777 server.bat
        
        new-host:hsqldb rdg$ ./server.sh
        3) in STS: a) project...clean jpetstore; b) run as ... Maven Package

        4) Started TC Server and got the following error:
        Code:
        SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
        SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
        Jul 27, 2010 10:17:37 PM org.apache.catalina.core.StandardContext listenerStart
        SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
        java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
        5) As directed by error message, went to http://www.slf4j.org/codes.html#StaticLoggerBinder where it said:
        Code:
          Failed to load class org.slf4j.impl.StaticLoggerBinder
        
        This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.
        
        As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.
        
        You can download SLF4J bindings from the project download page
        6) Added the following to jpetstore's pom.xml (I copied it from the pom.xml of the mvc-showcase sample:

        Code:
        <!-- Logging -->
        		<dependency>
        			<groupId>org.slf4j</groupId>
        			<artifactId>slf4j-api</artifactId>
        			<version>${org.slf4j-version}</version>
        		</dependency>
        		<dependency>
        			<groupId>org.slf4j</groupId>
        			<artifactId>jcl-over-slf4j</artifactId>
        			<version>${org.slf4j-version}</version>
        			<scope>runtime</scope>
        		</dependency>
        		<dependency>
        			<groupId>org.slf4j</groupId>
        			<artifactId>slf4j-log4j12</artifactId>
        			<version>${org.slf4j-version}</version>
        			<scope>runtime</scope>
        		</dependency>
        		<dependency>
        			<groupId>log4j</groupId>
        			<artifactId>log4j</artifactId>
        			<version>1.2.16</version>
        			<scope>runtime</scope>
        		</dependency>
        7) added the following to the properties section of pom.xml:
        Code:
        <org.slf4j-version>1.5.10</org.slf4j-version>
        8) After starting the tc server there were, at first glance, to errors. However nothing happened when I typed in FireFox: http://localhost:8080/jpetstore

        9) Looked more carefully and found this message in the log:
        Code:
        INFO: Initializing Spring FrameworkServlet 'petstore'
        [TomcatAspectJWeavingClassLoader@41584807] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
        Jul 27, 2010 10:27:48 PM org.apache.catalina.core.ApplicationContext log
        10) Googled and found a hit in a Spring Forum post at:
        http://forum.springsource.org/showthread.php?t=84682.

        11) I give up trying to figure out the error message. Instead, I remove the war file from TC server and then install the war back into TC server. When I start TC server it seems to give more messages that look healthy. I right click on index.html and select "Run on Server"

        12) jperstore starts up in a browser and works okay.

        13) I notice the url that jpetstore is running at: http://localhost:8080/org.springfram...ore/index.html

        14) Who would have ever guessed that url? I had assumed it would be http://localhost:8080/jpetstore.

        Am I the only one who has to do all this to get jpetstore to run?
        Last edited by RobertGloverJr; Jul 27th, 2010, 10:50 PM.

        Comment


        • #5
          and after all I have got home page but when I have pressed button Enter the Store
          this message is shown on the screen

          do you know solution for this, I use eclipse galileo tomcat 6 ?

          HTTP Status 500 -

          --------------------------------------------------------------------------------

          type Exception report

          message

          description The server encountered an internal error () that prevented it from fulfilling this request.

          exception

          org.apache.jasper.JasperException: /WEB-INF/jsp/spring/index.jsp(1,1) Unable to read TLD "META-INF/c.tld" from JAR file "file:/C:/Documents%20and%20Settings/Pero/Documents/springtestovi/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/org.springframework.samples.jpetstore/WEB-INF/lib/jstl-1.2.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
          org.apache.jasper.compiler.DefaultErrorHandler.jsp Error(DefaultErrorHandler.java:40)
          org.apache.jasper.compiler.ErrorDispatcher.dispatc h(ErrorDispatcher.java:407)
          org.apache.jasper.compiler.ErrorDispatcher.jspErro r(ErrorDispatcher.java:88)
          org.apache.jasper.compiler.Parser.processIncludeDi rective(Parser.java:345)
          org.apache.jasper.compiler.Parser.parseIncludeDire ctive(Parser.java:378)
          org.apache.jasper.compiler.Parser.parseDirective(P arser.java:486)
          org.apache.jasper.compiler.Parser.parseElements(Pa rser.java:1444)
          org.apache.jasper.compiler.Parser.parse(Parser.jav a:138)
          org.apache.jasper.compiler.ParserController.doPars e(ParserController.java:216)
          org.apache.jasper.compiler.ParserController.parse( ParserController.java:103)
          org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:154)
          org.apache.jasper.compiler.Compiler.compile(Compil er.java:315)
          org.apache.jasper.compiler.Compiler.compile(Compil er.java:295)
          org.apache.jasper.compiler.Compiler.compile(Compil er.java:282)
          org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:586)
          org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:317)
          org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
          org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
          javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
          org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:238)
          org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:250)
          org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1063)

          Comment


          • #6
            Personally, when that kind of message occurs I declare "workspace bankruptcy" and start all over again with a new, empty, never before used Eclipse workspace. In my experience, starting fresh solves many of these types of problems. Disclaimer: your mileage may vary. But it's what I would probably do, given that you have been fooling around with the workspace for a while tweaking things and now you finally know what you are doing and can avoid all the pitfalls you solved.
            A less Draconian measure might be to do a full "clean" and then shut down and restart eclipse.

            Comment


            • #7
              it was not

              Comment


              • #8
                It works!

                Hello,

                I have successfully run JPetStoreSample with PostgreSQL database. This is the list of steps:

                1. create project in Eclipse as new maven project from SCM and import JPetStoreSample from SpringSource svn

                2. in pom.xml change or add lines in <properties>:
                Code:
                <spring.version>3.0.7.RELEASE</spring.version>
                <jsp.version>2.2.1-b03</jsp.version>
                <ibatis.version>2.3.4.726</ibatis.version>
                <slf4j.version>1.5.11</slf4j.version>
                <postgresql.version>9.1-901-1.jdbc4</postgresql.version>
                and add dependencies:

                Code:
                <dependency>
                  <groupId>org.apache.ibatis</groupId>
                  <artifactId>ibatis-sqlmap</artifactId>
                  <version>${ibatis.version}</version>
                </dependency>
                <dependency>
                  <groupId>org.slf4j</groupId>
                  <artifactId>slf4j-api</artifactId>
                  <version>${slf4j.version}</version>
                  <scope>provided</scope>
                </dependency>
                <dependency>
                  <groupId>org.slf4j</groupId>
                  <artifactId>slf4j-log4j12</artifactId>
                  <version>${slf4j.version}</version>
                  <scope>provided</scope>
                </dependency>
                <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-jdbc</artifactId>
                  <version>${spring.version}</version>
                </dependency>
                <dependency>
                  <groupId>postgresql</groupId>
                  <artifactId>postgresql</artifactId>
                  <version>${postgresql.version}</version>
                </dependency>
                3. Change database driver to PostgreSQL in files:
                - dataAccessContext-local.xml

                Code:
                <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                	<property name="driverClassName" value="${jdbc.driverClassName}"/>
                	<property name="url" value="${jdbc.url}"/>
                	<property name="username" value="${jdbc.username}"/>
                	<property name="password" value="${jdbc.password}"/>
                </bean>
                - jdbc.properties (fill it with your data)

                Code:
                  jdbc.driverClassName=org.postgresql.Driver
                  jdbc.url=jdbc:postgresql://database_url
                  jdbc.username=database_user
                  jdbc.password=database_password
                4. correct files with errors in folder /WEB-INF/jsp/spring :
                - EditAccountForm.jsp, NewOrderForm.jsp, ShippingForm.jsp: remove space between "@" and "taglib" in second line
                Code:
                <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
                - in EditAccountForm.jsp change tag: </html:form> to </form>

                5. create new database in PostgreSQL and fill it with example data
                - SQL schema and example data are included in folder /org.springframework.samples.jpetstore/db/postgres/, in files: jpetstore-postgres-schema.sql and jpetstore-postgres-dataload.sql

                6. Run database server

                7. add Maven dependencies in Web Deployment Assembly properties:
                - menu Project -> Propeties -> Deployment Assembly -> button "Add" -> Java Build Path Entries -> Maven Dependencies

                8. Deploy project to Apache Tomcat in Eclipse:
                - Run as -> Run on server

                9. Voilą, it works!

                My environment configuration:
                - JDK 1.6.29
                - Eclipse Juno
                - database PostgreSQL 9.2
                - Maven 3.0
                - Apache Tomcat 7

                I hope that this "mini-tutorial" will help somebody.

                Best regards, pandominox
                Last edited by pandominox; Oct 19th, 2012, 05:59 AM.

                Comment

                Working...
                X