Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 977
Bart Vangeneugden Avatar asked Feb 23 '11 14:02

Bart Vangeneugden


1 Answers

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"/>
like image 101
Jan Avatar answered Sep 23 '22 04:09

Jan