在多个项目中划分Spring配置 [英] Divide Spring configuration across multiple projects

查看:140
本文介绍了在多个项目中划分Spring配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有很多项目使用相同的代码库(后端代码)。
只是前端往往是不同的。
我们决定最好的方法是将后端和前端分开到不同的项目中:引擎 Project_name



现在这些是Spring项目。因此,如果我们将Spring配置除以:
Database.xml Services.xml 将属于项目 Engine STRONG>。
特定的 Frontend.xml 将属于 Project_Name
要链接这些,我需要一个通用的 SpringBeans.xml 导入所有这些XML。



我尝试了以下目录结构:



引擎计划




  • 配置



      • Database.xml

      • 服务$ x
        $ / $>
        $ / $>
        $ / $ strong> Project_Name项目




        • 配置

          • SpringBeans.xml <


            • Frontend.xml





        SpringBeans.xml的内容简单:

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

        我设置了Eclipse,所以Project_Name项目引用了Engine项目。
        当我启动它时,会找到SpringBeans.xml,但是没有找到Engine项目中的XML文件(FileNotFoundException)。
        我还会注意到,在将引擎和前端代码分解成不同的项目之前,导入其他XML文件的原理就像一个魅力。



        所以我的问题给你:是否可以使不同的项目中的不同的Spring配置很好地一起玩?

        解决方案

        由于spring bean配置文件位于类路径中,您需要将前缀claspath添加到资源位置:


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



        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"/>
        

        这篇关于在多个项目中划分Spring配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆