Results 1 to 8 of 8

Thread: applicationcontext.xml necessary?

  1. #1

    Default applicationcontext.xml necessary?

    Is it recommended to physically have a file applicationcontext.xml or can I have all bean definitions in my app-servlet.xml file?

    In other words, does Spring look in applicationcontext.xml for anything special?

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    You need to physically have some context to boot from, but I guess you could have all your bean definitions in the app-servlet.xml file.

    It would be a better architecture though, to keep them separate. For bigger applications, or even just for integration testing, it even makes sense to split applicationcontext.xml into several files.

  3. #3
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    If you want to use Hibernate OSIV then you will need to register a ContextListener which needs an appContext file.

  4. #4

    Default

    I do have this in my web.xml, it's just that I'm not using a separate file (i.e. applicationContext.xml) -- is it enough (despite a bad design to have it all in one file)?

    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/sas-servlet.xml</param-value>
    	</context-param>
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>

  5. #5
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    If you are explicitly declaring the context, then no, you don't

  6. #6

    Default

    Thanks; I've been trying to minimize the number of XML files whenever it makes sense. Between Tiles, Hibernate, Spring, etc., the number of files can grow pretty quickly :-)

  7. #7
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    I've been trying to minimize the number of XML files whenever it makes sense. Between Tiles, Hibernate, Spring
    That's a good idea, but I wouldn't sacrifice modularity/readability. You can always separate the files into different directories.

  8. #8
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Gotta agree with katentim, that good old OO rule "each thing does one thing, and one thing well" applies to XML files as well

Posting Permissions

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