Where do Spring bean configuration files go in a Maven WAR module?

后端 未结 2 689
离开以前
离开以前 2020-12-13 05:25

I\'ve looked at a bunch of sample projects and I can\'t seem to tease out a common best practice. I\'ve seen Spring bean config files sometimes go in the src/main/web

2条回答
  •  既然无缘
    2020-12-13 05:47

    I think it is often good style to keep the code, its spring configuration an in a separate JAR that is included into the WAR, such that the WAR is basically empty but for web.xml and the like. This saves you from even asking this question. :-) You can reference those spring configurations with classpath: prefix.

    One advantage of this layout is that you can easily write Unittests that instantiate the complete Spring configuration of the WAR within the JAR. I would not necessarily recommend to use this for actual tests (although you can do integration tests this way), but you get a quick feedback when you accidentially break the overall structure of the config files without having to redeploy the application.

    If you really need to put spring configuration files into the WAR (perhaps since it also references beans that are implemented in the WAR itself) I would also put them into the normal resources path /WEB-INF/classes, for the reasons discussed above.

提交回复
热议问题