开发者

Divide Spring configuration across multiple projects

we have quite a few projects that use the same codebase (backend code). Just the frontend tends to be different. We decided that the best approach would be to seperate backend and frontend into different projects: Engine and Project_name

Now these are Spring-projects. So it would only seem logical if we divide the Spring configurations aswell: Database.xml, Services.xml would belong to the project Engine. And a specific Frontend.xml would belong to Project_Name. To link these up, I would need a generic SpringBeans.xml that imports all of these XML's.

I tried following directory structure:

Engine Project

  • Config
    • Spring
      • Database.xml
      • Services.xml

Project_Name Project

  • Config
    • SpringBeans.xml
    • spring
      • Frontend.xml

The contents of SpringBeans.xml are simply:

    <import resource="spring/Database.xml"/>
    <import resource="spring/Services.xml"/>
    <import resource="spring/Frontend.xml"/> 

I set up Eclipse so the Project_Name project references the Engine project. When I start it, SpringBeans.xml gets found, however the XML files in the Engine project aren't found (FileNotFoundException). I'll also note that before splitting up the Engine and Frontend code into different projects, the principle of importing other XML files worked like a charm.

So my question to you: Is it possible开发者_开发百科 to make different Spring configrations in different projects play together nicely?


Since the spring bean configuration files are in the classpath, you need to add the prefix claspath to the resource location:

<import resource="classpath:spring/Database.xml"/>
<import resource="classpath:spring/Services.xml"/>
<import resource="classpath:spring/Frontend.xml"/>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜