开发者

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 开发者_StackOverflow社区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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜