Announcement Announcement Module
Collapse
No announcement yet.
Importing Bean Definitions from One File Into Another Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Importing Bean Definitions from One File Into Another

    Hi.. i'm developing an app using spring, and my xxx-servlet.xml is getting bigger and bigger, i'm interested in the spring reference part 3.17. titled
    Importing Bean Definitions from One File Into Another
    (http://www.springframework.org/docs/...context-import)
    particularly in
    It's often useful to split up container definitions into multiple XML files. One way to then load an application context which is configured from all these XML fragments is to use the application context constructor which takes multiple Resource locations. With a bean factory, a bean definition reader can be used multiple times to read definitions from each file in turn.

    Generally, the Spring team prefers the above approach, since it keeps container configurations files unaware of the fact that they are being combined with others.
    but i can't seem to find an example of using multiple resource locations in the application context constructor... (not using the import statement)

    thank you...

  • #2
    There's a servlet initialization parameter available called contextConfigLocation. It works just as the contextConfigLocation parameter for the ContextLoaderListener/Servlet. I don't think it's documented enough, I'll add this somewhere this week.

    So:

    Code:
    <servlet>
      <servlet-name>xxx</servlet-name>
      <servlet-class>org.spr...DispatcherServlet</servlet-class>
      <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/contextOne.xml, /WEB-INF/contextTwo.xml</param-value>
      </init-param>
    </servlet>
    I assume you're already using the ContextLoaderListener/Servlet to separate your business-tier beans from the web-tier beans? If not, this is another (and more convenient way to bring a logical separation between the different layers in your app).

    regards,
    Alef Arendsen

    Comment


    • #3
      thank you very much... yes i already separated them.. but even though i already separate its still to large to put in one xml file.. but thank you again this is exactly what im looking for

      Comment


      • #4
        Originally posted by Alef Arendsen
        Code:
        <servlet>
          <servlet-name>xxx</servlet-name>
          <servlet-class>org.spr...DispatcherServlet</servlet-class>
          <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/contextOne.xml, /WEB-INF/contextTwo.xml</param-value>
          </init-param>
        </servlet>
        Concerning this feature I have a question. I have the following scenario:
        - within an EAR file is one ejb-jar file and one war file
        - the war-file manifest refers to the ejb-jar file in its Class-Path entry
        - I have a spring configuration file in the root of my ejb-jar file
        - I have the web configuration (Spring MVC) in the war (as usual)

        Now I would like to access beans defined in the configuration within my ejb-jar file from the controllers defined in my war.
        Indirectly I could use remote/local EJB access. However, can I access the configuration file directly? So I could directly use the POJO handlers.
        Trying out the above mentioned code did not work. I guess resolving across jars seems to be more difficult.

        Any idea anyone?

        Regards,
        Andreas

        P.S.: Using JBoss 4.01SP1

        Comment


        • #5
          You can solve this problem by playing with the packaging. I don't have the documentation at hand but I know that the official docs from jboss mentioned about different XML descriptors that affect the EAR class-loader - basically you will have the EJB and WEB components in the same namespace and accessible to one another.

          Hope it gives you some pointers :?

          Comment


          • #6
            Costin,

            thanks for your help. I feared that I might have to tackle the classloading
            I thought there might possibly be a "springish" solution. Maybe using import tags or the like (but import does not seem to help here, according to the documentation).

            Regards,
            Andreas

            Comment


            • #7
              There isn't much you can do about the CL problem. The configuration files are loaded through the CL mechanism and in your scenario these means the configuration files are invisible between the web and ejb classloader.
              By using the (awful in my opinion) extension from JBoss you should be able to tackle this problem after some try-and-error episodes. You can also try to duplicate your files when you do packaging - copy the configuration files in both web and ejb packages.
              It's messy but it could work.

              Comment

              Working...
              X