Home > Enterprise >  Spring batch - overriding jobrepository in context.xml
Spring batch - overriding jobrepository in context.xml

Time:01-12

Like described in the linked article below, with Java configuration it is possible to override the JobRepository bean by extending DefaultBatchConfigurer and overriding createJobRepository.

How can this be achieved in a context.xml file where the jobrepository bean is defined like this

<bean id="jobRepository_new"
    >
    <property name="databaseType" value="Oracle" />
    <property name="dataSource" ref="dataSource-batch" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="tablePrefix" value="BATCH_" />
    <property name="lobHandler" ref="oracleLobHandler" />
</bean>

?

Can't serialize access for this transaction when running single job, SERIALIZED isolation level

CodePudding user response:

Unlike with the Java configuration style, there is nothing provided by default (that you can override) when you use the XML configuration style.

So you just need configure the job repository bean as needed like shown in the snippet you shared.

CodePudding user response:

Any given Spring context can only have one bean for any given id or name.

  • In the case of the XML id attribute, this is enforced by the schema validation.
  • In the case of the name attribute, this is enforced by Spring's logic.

However, if a context is constructed from two different XML descriptor files, and an id is used by both files, then one will "override" the other. The exact behaviour depends on the ordering of the files when they get loaded by the context.

So while it's possible, it's not recommended. It's an error and fragile, and you'll get no help from Spring if you change the ID of one but not the other.

  • Related