user7094
user7094

Reputation:

Spring Context wildcard in unit tests

We have a project setup here which uses Maven profiles quite extensively. We're using Spring, and although we mostly have an annotation-based configuration there are a few XML configuration files needed.

These Spring XML config files are pulled in with various different profiles, and in the actual web application they're all put in WEB-INF/spring and loaded up with classpath:spring/spring-*.xml. This works fine.

The problem is unit testing: I want to test a variety of different profiles, and Spring seems to have an issue with a wildcard specification like that when the files are spread over several directories.

The easiest solution I think would just be to specify each config file in the @ContextConfiguration test annotation, but unfortunately if one is missing Spring throws an exception, and there doesn't seem to be a way of turning this off.

The other thing I thought was potentially dumping all spring config files into one folder before running the tests, but that seems a bit of a kludge.

I was just wondering if anyone else had any experience of this problem and any workarounds.

Upvotes: 1

Views: 2096

Answers (1)

user7094
user7094

Reputation:

It seems that the Spring guys have thought of this already.

You can use the syntax:

classpath*:spring/spring-*.xml

Which seems to work properly.

Upvotes: 4

Related Questions