Announcement Announcement Module
Collapse
No announcement yet.
IllegalStateException: No Scope registered for scope 'job' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IllegalStateException: No Scope registered for scope 'job'

    Hello,

    I have an error with my spring configuration at startup
    when i have one applicationContext.xml that use spring Batch
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath:applicationContext.xml</param-value>
    	</context-param>
    with a job
    Code:
    	<job id="myJob">
    		<listeners>
    			<listener>
    				<beans:bean
    					class="xxx.listener.LogInfoJobListener"
    					scope="job">
    				</beans:bean>
    			</listener>
    		</listeners>
    		<step id="myJobStep1">
    			<tasklet>
    				...
    			</tasklet>
    		</step>
    	</job>
    It works well
    but if i added a second applicationContext-ws.xml (that used CXF - but even empty)
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath:applicationContext.xml,classpath:applicationContext-ws.xml</param-value>
    	</context-param>
    I get at startup
    Caused by: java.lang.IllegalStateException: No Scope registered for scope 'job'

    Have you an idea ?
    Thanks

  • #2
    Hi there. Not sure if this could help solve your problem, but in your second context config location, you have a comma separating your xml files. Try removing that comma and bring the second xml file down a line. See if you get the same error.

    Comment


    • #3
      Hello,

      I try this solution, but it changes nothing.
      I think the scope "job" does'nt exist in spring batch documentation.
      So maybe if i just remove it, it works and it seems to have no other effect.
      Do you confirm ?

      Comment


      • #4
        I have the same problem "no scope registered for scope job" when creating an itemReader. Any updates on this? Or do I somehow have to manually register the JobScope??
        (Spring-Batch 3.0.0.RELEASE)
        Code:
        @Bean
        @Scope("job")
        public JpaItemWriter<T> jpaItemWriter(EntityManagerFactory emf) {
        JpaItemWriter<T> writer = new JpaItemWriter<T>();
        writer.setEntityManagerFactory(emf);
        return writer;
        }

        Comment


        • #5
          The job scope isn't being registered automatically at the moment when using java config. I logged a JIRA issue for this: https://jira.spring.io/browse/BATCH-2253

          As a temporary workaround you can register the scope manually:

          Code:
              private JobScope jobScope = new JobScope();
          
              @Bean
              public JobScope jobScope() {
                  jobScope.setAutoProxy(false);
                  return jobScope;
              }
          But what is actually your use case for using job scope here for your writer? I think using step scope is probably fine?
          Last edited by jpraet; Jun 4th, 2014, 03:25 PM.

          Comment


          • #6
            membersound,

            A note to what was mentioned about the JobScope issue. The way you've defined your bean to be job scoped won't work as you expect. By default, the @Scope's proxyMode is none. Because of this, it will be instantiated immediately which won't be what you're expecting. You need to specify the proxy mode to be either interfaces or target class for the late instantiation to work.

            Comment

            Working...
            X