srinannapa
srinannapa

Reputation: 3207

Overriding the spring configuration file present in a jar for Junit

I have bean definitions(x1.spring.xml) present in one of the dependency modules of my project.

Now I had to write Junit which uses x1.spring.xml file present in the jar. I would like to override some bean entires in x1.spring.xml , so I create the same package structure in test/src --> and placed the file x1.spring.xml with my new modifications.

But when I execute the junit , program is taking the one present the jar but not the one present in test/src folder. I maintained the same package structure as jar ( thinking it will override the one present in the jar)

Upvotes: 0

Views: 713

Answers (1)

Emerson Farrugia
Emerson Farrugia

Reputation: 11353

If you follow Maven conventions, i.e. ${basedir}/src/main/resources and ${basedir}/src/test/resources, then files in the latter location are put earlier in the classpath, so the @SpringJUnit4ClassRunner would find the test file first. It sounds like you're not using conventional directories, in which case make sure that you've configured the resources and testResources build elements correctly. See the POM reference for details.

Or just call the test file something else to keep things simple, if this is a top level resource configured in the @SpringJUnit4ClassRunner.

Upvotes: 2

Related Questions