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

Still need in-memory DB or datasource setting when use MongoDB as JobRepository #4728

Open
weiz-cn opened this issue Dec 3, 2024 · 2 comments
Labels
status: feedback-provided Issues for which the feedback requested from the reporter was provided type: bug

Comments

@weiz-cn
Copy link

weiz-cn commented Dec 3, 2024

Please do a quick search on Github issues first, there might be already a duplicate issue for the one you are about to create.
If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description
Still need in-memory DB or datasource setting when use MongoDB as JobRepository.
Environment
Spring batch 5.2, Java 17

Steps to reproduce
Create a spring-boot application, use MongoDB as JobRepository following https://github.com/spring-projects/spring-batch/blob/main/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java

Do not setup any datasource or in-memory DB, start the springboot application. Got following error:

2024-12-03T09:46:46.892+08:00  WARN 65662 --- [spring-batch-demo] [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobLauncherController': Unsatisfied dependency expressed through field 'jobLauncher': Error creating bean with name 'jobLauncher': Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'
2024-12-03T09:46:46.894+08:00  INFO 65662 --- [spring-batch-demo] [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2024-12-03T09:46:46.899+08:00  INFO 65662 --- [spring-batch-demo] [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-12-03T09:46:46.907+08:00 ERROR 65662 --- [spring-batch-demo] [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Process finished with exit code 1

If I add hsqldb dependency to pom.xml. The application can start successfully. I tried to start the job, and I can see MongoDB is used as JobRepository.

Expected behavior
A clear and concise description of what you expected to happen.

Minimal Complete Reproducible example
https://github.com/weiz-cn/spring-batch-demo
You need a MongoDB as JobRepository to start the application

@weiz-cn weiz-cn added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Dec 3, 2024
@fmbenhassine
Copy link
Contributor

Thank you for reporting this. Indeed, this is a design issue with the Java configuration style that was inherited from the early version of EnableBatchProcessing (from which DefaultBatchConfiguration was designed similarly for consistency).

That said, there should be no issue with the XML configuration style where you can define the mongo job repository without the need for a datasource:

<bean id="jobRepository"
 class="org.springframework.batch.core.repository.support.MongoJobRepositoryFactoryBean"
 p:mongoOperations-ref="mongoOperations" p:transactionManager-ref="mongoTransactionManager" />

Have you tried that?

@fmbenhassine fmbenhassine added status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter and removed status: waiting-for-triage Issues that we did not analyse yet labels Dec 3, 2024
@weiz-cn
Copy link
Author

weiz-cn commented Dec 4, 2024

p:transactionManager-ref

I got this, even I set spring.main.allow-bean-definition-overriding=true

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'jobRepository', defined in class path resource [beans.xml], could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

@fmbenhassine fmbenhassine added status: feedback-provided Issues for which the feedback requested from the reporter was provided and removed status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter labels Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Issues for which the feedback requested from the reporter was provided type: bug
Projects
None yet
Development

No branches or pull requests

2 participants