Skip to content

Provide a way to specify the class loader to be used by a ClassPathXmlApplicationContextFactory [BATCH-2182] #1417

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

Closed
spring-projects-issues opened this issue Feb 21, 2014 · 2 comments
Labels
in: infrastructure status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

Mauro Molinari opened BATCH-2182 and commented

A ClassPathXmlApplicationContextFactory creates ClassPathXmlApplicationContext instances. The latter, by extending DefaultResourceLoader would allow to specify the class loader to use to locate resources. It would be very useful if the factory and the corresponding ClasspathXmlApplicationContextsFactoryBean (which, IMHO, should better be called ClassPathXmlApplicationContextFactoryFactoryBean, since it's a FactoryBean that creates factories and also would need an upper case "P" in "ClassPath") allowed to specify the class loader to use. This would allow to create an AutomaticJobRegistrar which registers jobs defined in child contexts loaded through a suitable class loader (which may in turn load classes at runtime from hot-deployed JARs, for instance).

Being able to specify just one class loader on the FactoryBean for all created factories would be better than nothing.

Right now I have to write my own FactoryBean and factory to achieve this, but I think that supporting this out-of-the-box should be quite simple and valuable.

By the way, I see that with 3.0.0.M2 ClassPathXmlApplicationContextFactory has been deprecated in favour of GenericApplicationContextFactory, which creates generic ConfigurableApplicationContexts. This enhancement might give a reason to revert the deprecation on ClassPathXmlApplicationContextFactory and add some additional value to it...


Affects: 2.1.9

@spring-projects-issues
Copy link
Collaborator Author

Mauro Molinari commented

Also, to ease extension it would be useful if org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean provided a hook to change the factory implementation, even if it were just an extension of org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextFactory. In fact, to work around my use case, the best would be to extend ClassPathXmlApplicationContextFactory and override its prepareContext(ConfigurableApplicationContext, ConfigurableApplicationContext) method to set the class loader before refreshing, but I can't change the fact that org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean.getObject() goes straight with a new ClassPathXmlApplicationContextFactory(). So I have to apply some dirty workarounds to avoid to copy and paste a lot of code.

Last but not least, some getters on these configuration classes for private fields would also help extension :-)

@fmbenhassine
Copy link
Contributor

ClassPathXmlApplicationContextFactory has been deprecated since v3 and will be removed in v5 (see #3836), so I see no value in putting efforts on it for the rest of its short life.

@fmbenhassine fmbenhassine added status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details and removed status: waiting-for-triage Issues that we did not analyse yet labels Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: infrastructure status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants