Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load a spring configuration from another module

I'm working on a spring application that contains submodules, roughly looking like the following:

project
|-- module1
|   |-- src
|   |   `-- main
|   |       |-- java
|   |       `-- resources
|   |           |-- applicationContext.xml
|   |           `-- web.xml
|   `-- pom.xml
|-- module2
|   |-- src
|   |   `-- main
|   |       |-- java
|   |       `-- resources
|   |           `-- batch-jobs.xml
|   `-- pom.xml
`-- pom.xml

module1 contains the web app configuration. module2 contains using spring-batch to run batch jobs, which are configured in batch-jobs.xml.

Inside applicationContext.xml I have the following line:

<import resource="classpath*: batch-jobs.xml" />

As far as I can tell, this file is being loaded. I assume this because previously I was using classpath: batch-jobs.xml (without the *) and it couldn't find the file.

In spite of loading this file, I get a NoSuchBeanDefinitionException. If I copy everything from batch-jobs.xml over to applicationContext.xml, it works fine.

like image 634
Jon Avatar asked Jan 21 '14 13:01

Jon


Video Answer


1 Answers

When you use the asterix like this

<import resource="classpath*: batch-jobs.xml" />

it ignores files it can't find (among other things)

See e.g. this question for details

Make sure you refer to its spring configuration xml with leading slash, like this:

<import resource="classpath:/batch-jobs.xml" />

If it still complains about file batch-jobs.xml not found make sure you have module 2 jar on your classpath (add dependency on module2 to module 1).

like image 108
František Hartman Avatar answered Sep 19 '22 20:09

František Hartman