Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: StepListener is a marker interface so it cannot be applied directly to a step [BATCH-1591] #1993

Closed
spring-issuemaster opened this issue Jun 28, 2010 · 5 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jun 28, 2010

Daniel Soneira opened BATCH-1591 and commented

Was: StepParserStepFactoryBean - ClassCastException when using POJO listener

<step>
  <tasklet>
    <listeners>
       <listener ref="pojoListener" before-step-method="before" after-stop-method="after"/>
    </listeners>
  </tasklet>
</step>

<bean id="pojoListener" class="com.example.MyListener"/>

MyListener is a POJO class and does not implement any specific interface.

A ClassCastException occurs in StepParserStepFactoryBean#configureAbstractStep on the following line:
newListeners[i++] = (StepExecutionListener) listener;

The listener is of type StepListener (behind AOP proxy).

In contrast to BATCH-1588 the listener is not ignored but the exception prevents the application to start up.
The problem does not occur for listeners implementing the Interface directly or annotated listeners.

--------- Possible documentation error ----------
In chapter "5.1.10. Intercepting Step Execution" the following is stated:

"Any class that implements the StepListener interface (or an extension thereof) can be applied to a step via the listeners element"

That seems to contradict the code - the same ClassCastException occurs when the using a listener that implements StepListener directly.


Affects: 2.1.1

Attachments:

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 28, 2010

Dave Syer commented

It works for me. Were you using a snapshot build (so you include the fix for BATCH-1588)?

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 29, 2010

Daniel Soneira commented

No, I didn't use a snapshot when reporting the error since it seemed independent of that fix and I simply changed the return values during my debugging session by hand to "emulate" the fix :)

That being said, I downloaded the following two jars and the exception is still thrown:
spring-batch-core-2.1.2.CI-20100628.190807-67.jar
spring-batch-infrastructure-2.1.2.CI-20100628.190807-67.jar

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 29, 2010

Daniel Soneira commented

My configuration and source of classes involved.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 29, 2010

Dave Syer commented

You have a listener defined simply as

public class SimpleStepListener implements StepListener {

}

So it is no surprise that we see a class cast exception since it is not a StepExecutionListener. If you remove that listener from the config everything works I think.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 29, 2010

Daniel Soneira commented

I added the SimpleStepListener just to prove that the documentation is wrong - see my description in the original report (section "Possible documentation error").
I'm not quite sure why this works today but you're actually right - if you take out that listener it works (didn't when I tried it yesterday... nevermind).
So aside from the documentation everything is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.