Results 1 to 7 of 7

Thread: Importing Bean Definitions from One File Into Another

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3

    Default

    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

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote 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

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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 :?
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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

  7. #7
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •