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
JSR-352 support does not work for custom infrastructure [BATCH-2290] #1312
Comments
Tobias Flohre commented A suggestion how to solve this: baseContext doesn't need to be static. When used with the ServiceLoader mechanism, it will get a reference to a static ApplicationContext, so we don't win that much if baseContext itself is static as well. What do you think? |
Michael Minella commented The Spring Batch implementation of JSR-352 was never intended for you to wire up your own JsrJobOperator. The spec states that you are to get a handle of it via BatchRuntime so on the JSR side, that is all that is supported right now. I know there is an issue with the JSR to make that more DI friendly, but I'm unaware of it's state. We do provide the ability to override the components in the BaseContext if you like. That being said, you are correct in that baseContext within the However, to re-iterate, if you are looking to conform to JSR-352, the entry point for batch jobs is via |
Tobias Flohre commented I would guess that batchContext needs a parent to get the batch infrastructure from. And that would be my main ApplicationContext. I will try it out to confirm that. Yes, you're right, Spring Batch implements the spec, so this is more a feature request than a bug. But for me it's quite a standard use case: customers that are already using Spring Batch and are now looking for a way to implement JSR-352 jobs. And I know, if I don't use the BatchRuntime for getting a JobOperator, I'm not spec-compliant, but I don't like the BatchRuntime-thing anyway ;-). And everything from the point where I have the JobOperator is spec-compliant. |
Michael Minella commented To be 100% honest, I'd ask those customers what they are looking to get out of JSR-352 in the first place if they are already Spring Batch users. However, that's a topic for another day... |
Tobias Flohre commented I think it's more about having options. Anyway, I just checked: |
Tobias Flohre commented For reference: I subclassed the JsrJobOperator to make it work for me, here it is: https://github.com/codecentric/spring-boot-starter-batch-web/blob/master/src/main/java/de/codecentric/batch/jsr352/CustomJsrJobOperator.java. |
Michael Minella commented Upon reflection, one thing we could do to allow for a bit more freedom and still being spec compliant is to allow the user to specify via a JVM property the location of a base context. Currently we only allow the ability to override it at a job level, but I don't see why we couldn't allow a global one to be set at the JVM level. Thoughts? |
Michael Minella commented Added the ability to override the base context configuration on a global scale: 4861d94 |
Tobias Flohre commented Sorry for replying a little late. I still don't see what's not spec-compliant in the solution I provided here: https://github.com/codecentric/spring-boot-starter-batch-web/blob/master/src/main/java/de/codecentric/batch/jsr352/CustomJsrJobOperator.java. |
Michael Minella commented Re-evaluating the way the manually wired instance works based on comments by Tobias Flohre. |
Tobias Flohre commented My implementation also adds some listeners to jobs, which of course is not part of this issue. The two things you need to do is:
|
Michael Minella commented Tobias Flohre, I've already removed the static from baseContext in this commit: c104693. The part I was reconsidering was I had not implemented |
Michael Minella commented Made |
Tobias Flohre opened BATCH-2290 and commented
I am trying to integrate JSR-352 support in our existing Spring Batch infrastructure (existing JobRepository, JobExplorer, TaskExecutor, TransactionManager and so on) and I'm stuck.
The JsrJobOperator has a constructor to pass in the dependencies, but when using the start-method afterwards, baseContext is null (it's only initialized in the other constructor), and I get an error regarding the bean creation of the jobExplorer.
I want to use my existing ApplicationContext as baseContext. If I don't miss something, that's not possible.
Here the exception:
Affects: 3.0.1
Referenced from: commits 4861d94, 92e551e, c104693, d3410c9
1 votes, 3 watchers
The text was updated successfully, but these errors were encountered: