Announcement Announcement Module
Collapse
No announcement yet.
while running batch application through from servlet i am getting this error......... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • while running batch application through from servlet i am getting this error.........

    while running batch application through from servlet i am getting this error.........

    java.lang.NullPointerException
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:85)
    at com.mypack.UploadServlet.doPost(UploadServlet.java :174)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

    and my servlet is like this...

    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("helloWorldJob.xml" );
    context.getAutowireCapableBeanFactory().autowireBe anProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    org.springframework.batch.core.Job job;
    job = (org.springframework.batch.core.Job) context.getBean("helloWorldJob");

    JobParametersBuilder builder = new JobParametersBuilder();
    JobParameters jobParameters = builder.toJobParameters();
    JobLauncher launcher = new SimpleJobLauncher();
    try {
    JobExecution jobExecution = launcher.run(job, jobParameters);
    out.println(jobExecution.getExecutionContext());
    out.println(jobExecution.getExitStatus());
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }

    and memory-repository is....

    <bean id="jobRepository-transactionManager"
    class="org.springframework.batch.support.transacti on.ResourcelessTransactionManager"/>
    <bean id="jobLauncher"
    class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor">
    <bean class="org.springframework.core.task.SimpleAsyncTa skExecutor" />
    </property>
    </bean>

    helloWorldJob.xml is......

    <import resource="MEMORY-JOBREPOSITORY.xml"/>
    <!-- <import resource="DB-JOBREPOSITORY.xml"/>-->

    <bean id="hello" class="com.mypack.PrintTasklet">
    <property name="message" value="Hello"/>
    </bean>
    <bean id="world" class="com.mypack.PrintTasklet">
    <property name="message" value=" World!"/>
    </bean>

    <!-- <bean id="dynamicJobParameters"
    class="com.ecomputercoach.DynamicJobParameters" />-->

    <!-- <batch:job id="helloWorldJob" job-repository="jobRepository" incrementer="dynamicJobParameters">-->
    <batch:job id="helloWorldJob" job-repository="jobRepository">
    <batch:step id="step0" next="step1">
    <batch:tasklet ref="hello"
    transaction-manager="jobRepository-transactionManager" />
    </batch:step>
    <batch:step id="step1">
    <batch:tasklet ref="world"
    transaction-manager="jobRepository-transactionManager" />
    </batch:step>
    </batch:job>

    </beans>



    can any body help on this.......
    Last edited by Rams; May 9th, 2011, 07:30 AM.

  • #2
    this isn't the proper way to use Spring in a web environment, you should take a look at the Spring reference documentation before asking on the appropriate Spring forum (this isn't directly related to Spring Batch). In short, you should use a ContextLoaderListener to bootstrap the Spring application context and WebApplicationContextUtils to get access to the application context from your servlet.

    Comment


    • #3
      Hi arno,

      i m new to this..

      can you please give more info this...
      how to use CotextLoaderListener to bootstrap the spring application contex and webapplicationconextutils to get access to the applicatio cntext from my servlet.

      Regards,
      Rams

      Comment


      • #4
        is the following snippet is correct... please correct me....

        ServletContext context = getServletContext();
        WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContex t(context);
        JobLauncher launcher = (JobLauncher ) applicationContext.getBean("helloWorldJob.xml");
        Job job = (Job ) applicationContext.getBean("helloWorldJob");
        JobParameters jobParameters= new JobParametersBuilder().addDate("schedule.time", date).toJobParameters();
        try
        {
        String status = launcher.run(job,jobParameters);
        }
        catch(Exceptop e)
        {

        }

        I tried earlier like this eventhough it is showing same error..........correct me... which one can i use

        Comment


        • #5
          did you configure the ContextLoaderListener in your web.xml before using WebApplicationContextUtils? if not, take a look at here: http://static.springsource.org/sprin...context-create

          Comment


          • #6
            i had changed web.xml like this eventhough it is giving same error

            web.xml

            <?xml version="1.0" encoding="UTF-8"?>
            <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
            <display-name>
            UploadFile</display-name>
            <servlet>
            <description>
            </description>
            <display-name>
            UploadServlet</display-name>
            <servlet-name>UploadServlet</servlet-name>
            <servlet-class>
            com.mypack.UploadServlet</servlet-class>
            </servlet>
            <servlet-mapping>
            <servlet-name>UploadServlet</servlet-name>
            <url-pattern>/UploadServlet</url-pattern>
            </servlet-mapping>
            <welcome-file-list>
            <welcome-file>upload.html</welcome-file>
            </welcome-file-list>

            <!-- <servlet>-->
            <!-- <servlet-name>context</servlet-name>-->
            <!-- <servlet-class>org.springframework.web.context.ContextLoade rServlet</servlet-class>-->
            <!-- <load-on-startup>1</load-on-startup>-->
            <!-- </servlet>-->

            <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/helloWorldJob.xml</param-value>
            </context-param>

            <listener>
            <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
            </listener>
            </web-app>

            and error is......

            java.lang.NullPointerException
            at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:85)
            at com.mypack.UploadServlet.doPost(UploadServlet.java :174)
            at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
            at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
            at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
            at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
            at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:857)
            at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
            at java.lang.Thread.run(Unknown Source)

            Comment


            • #7
              I doubt this works (you shouldn't even get a NullPointerException) :

              Code:
              JobLauncher launcher = (JobLauncher ) applicationContext.getBean("helloWorldJob.xml");
              did you check the source code to see what the SimpleJobLauncher misses to throw a NullPointerException?

              Comment


              • #8
                SEVERE: Servlet.service() for servlet UploadServlet threw exception
                org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'helloWorldJob.xml' is defined
                at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:387)
                at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedLocalBeanDefinition(AbstractB eanFactory.java:971)
                at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:246 )
                at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
                at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
                at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:880)
                at com.mypack.UploadServlet.doPost(UploadServlet.java :132)
                at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
                at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
                at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
                at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
                at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
                at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
                at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
                at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
                at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
                at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
                at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:857)
                at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
                at java.lang.Thread.run(Unknown Source)


                JobLauncher launcher = (JobLauncher ) applicationContext.getBean("helloWorldJob.xml");

                the above statement showing error..
                pls correct me...........

                Comment


                • #9
                  here is uploadservlet code.....

                  PrintWriter out = response.getWriter();
                  JobExecution status =null;
                  Date date=null;
                  ServletContext context = getServletContext();
                  WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContex t(context);
                  JobLauncher launcher = (JobLauncher ) applicationContext.getBean("helloWorldJob.xml");
                  Job job = (Job ) applicationContext.getBean("helloWorldJob");

                  JobParameters jobParameters= new JobParametersBuilder().addDate("schedule.time", date).toJobParameters();
                  try
                  {
                  status = launcher.run((org.springframework.batch.core.Job)j ob,jobParameters);

                  }
                  catch(Exception e)
                  {

                  }

                  response.setContentType("text/html");
                  out = response.getWriter();
                  out.print(status.getExecutionContext());
                  out.println(status.getExitStatus());
                  out.flush();
                  String s="Hello, spring batch!";
                  String s1="hp";
                  String s2="spring batch! done";
                  //PrintWriter out = response.getWriter();

                  out.println(s);

                  Comment


                  • #10
                    look up the job launcher with its bean name, not with the name of the file!
                    Code:
                    JobLauncher launcher = (JobLauncher ) applicationContext.getBean("jobLauncher");

                    Comment


                    • #11
                      i had changed the satement from
                      JobLauncher launcher = (JobLauncher ) applicationContext.getBean("helloWorldJob.xml");
                      to like this..
                      JobLauncher launcher = (JobLauncher ) applicationContext.getBean("jobLauncher");
                      now the error is....

                      SEVERE: Servlet.service() for servlet UploadServlet threw exception
                      java.lang.ClassCastException: org.springframework.batch.core.job.flow.FlowJob
                      at com.mypack.UploadServlet.doPost(UploadServlet.java :133)
                      at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
                      at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
                      at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
                      at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
                      at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
                      at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
                      at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
                      at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
                      at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
                      at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
                      at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:857)
                      at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
                      at java.lang.Thread.run(Unknown Source)

                      it is showing the error in this line

                      Job job = (Job ) applicationContext.getBean("helloWorldJob");

                      Comment


                      • #12
                        i had changed the satement from
                        JobLauncher launcher = (JobLauncher ) applicationContext.getBean("helloWorldJob.xml");
                        to like this..
                        JobLauncher launcher = (JobLauncher ) applicationContext.getBean("jobLauncher");
                        now the error is....

                        SEVERE: Servlet.service() for servlet UploadServlet threw exception
                        java.lang.ClassCastException: org.springframework.batch.core.job.flow.FlowJob
                        at com.mypack.UploadServlet.doPost(UploadServlet.java :133)
                        at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
                        at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
                        at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
                        at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
                        at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
                        at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
                        at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
                        at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
                        at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
                        at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
                        at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:857)
                        at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
                        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
                        at java.lang.Thread.run(Unknown Source)

                        it is showing the error in this line

                        Job job = (Job ) applicationContext.getBean("helloWorldJob");

                        please correct me...

                        Comment


                        • #13
                          you must use the org.springframework.batch.core.Job interface, not something else (like the Quartz' job interface). Note none of your questions is related to Spring Batch, it's only Spring specific, and even about Java now.

                          Comment


                          • #14
                            boss sorry for trouble...

                            job package imported....

                            now it is showing the error is.....

                            SEVERE: Servlet.service() for servlet UploadServlet threw exception
                            java.lang.IllegalArgumentException: Parameter must not be null.
                            at org.springframework.util.Assert.notNull(Assert.jav a:112)
                            at org.springframework.batch.core.JobParametersBuilde r.addDate(JobParametersBuilder.java:78)
                            at com.mypack.UploadServlet.doPost(UploadServlet.java :136)
                            at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
                            at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
                            at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
                            at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
                            at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
                            at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
                            at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
                            at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
                            at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
                            at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
                            at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:857)
                            at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
                            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
                            at java.lang.Thread.run(Unknown Source)

                            Comment


                            • #15
                              Hi arno,

                              Can you pls let me know if running job thru memory-job repository will support multi-threading and production env.

                              Regards, Rams

                              Comment

                              Working...
                              X