Announcement Announcement Module
Collapse
No announcement yet.
How to load context files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to load context files

    Hi,

    I am trying to load several context files from various sub projects into a war, but there seem to be a lot of hitches, I think I've got most of it working, but some beans don't seem to get loaded.

    Please see the zipped project

    I am currently getting this error:

    [WARNING] [talledLocalContainer] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'showLocalitiesController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire method: public void com.djpteam.bid.web.ShowLocalitiesController.setLo calityService(com.djpteam.bid.service.LocalityServ ice); nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [com.djpteam.bid.service.LocalityService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    There don't appear to be any other errors. You can see the gps.log in the zipped project.

    I suspect that the following configuration in web.xml is at fault as I have not seen a clear indication as to how to load configuration from the jarred classpath artifacts.

    Code:
        <listener>
        	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener> 
        
        <context-param>
        	<param-name>contextConfigLocation</param-name>
        	<param-value>
        	 	classpath*:**/*context.xml
    			classpath:service-context.xml
    			classpath:dao-context.xml
        	</param-value>
        	
        </context-param>
    It is either this or some other detail in the configuration. Can anyone spot what's wrong?

    thanks
    Last edited by largesnike; Jan 13th, 2011, 01:38 AM. Reason: bad title

  • #2
    its seems that your module doesn't recognize / cannot access the the other context.
    i think its better if you use import in your root context, so any of different context can be seen as one context configuration.
    <import resource="your-another-xml.xml"/>

    Comment


    • #3
      Well, yes, I agree.

      I'll have a crack at doing the direct import, but it would be a very much less than ideal solution as it would completely tie my modules together (relying on direct imports from files that are not in the same module).

      I was rather hoping that I could use the classpath* syntax as it would import all *-context.xml files in the classpath, but this doesn't seem to work. I was hoping that some classpath/context guru would save me from my incompetance.

      Comment


      • #4
        Actually, ant-style wildcards and classpath* are known to not work too well together, thanks to underlying Java issues. Take a look here for details.

        Typically when I use classpath*, I expect that the config files will be in a fixed location (classpath*:/spring/*-config.xml, for example). For that matter, by using imports, you can get away with a fixed name for each file (classpath*:/module-config.xml).

        Hope this helps
        - Don

        Comment


        • #5
          Ah, so if I were to place the files one directory down (i.e., by having /spring/ in the path, or similar) it might work?

          I didn't really want to have fixed names for the files, I just wanted to have something like: "classpath*:**/*context.xml" to get any file that ends with context.xml. I only used fixed names in web.xml to try to get the context to find them.

          So, if I were to have a single reference in web xml like so:

          Code:
          <listener>
              	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
              </listener> 
              
              <context-param>
              	<param-name>contextConfigLocation</param-name>
              	<param-value>
              	 	classpath*:**/spring/*context.xml
              	</param-value>
              	
              </context-param>
          and then put all my context files behind /spring/ directories, things might start working?

          Comment


          • #6
            From what I have working, it appears you cannot wildcard the name of context files that exist in another jar and not directly in the war. You can only wildcard their path.

            You can however wildcard the name of context files if they exist directly in the war.

            So for example:

            <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/SampleWar-context.xml
            classpath*:/SampleClientInt-context.xml</param-value>
            </context-param>

            SampleClientInt-context.xml exists in another jar within the war and so I cannot wildcard it's name. Then I put imports within that context file so bootstrapping one will bootstrap the rest.

            Hope that helps....jay

            Comment


            • #7
              well I've tried the direct import as you suggested.

              it seems that the imported files need to be relative to the importing file, so if I have:

              /usr/local/apache-tomcat-6.0.29/webapps/bid-web/WEB-INF/classes/spring/web-context.xml

              and I want to import a file in...

              /usr/local/apache-tomcat-6.0.29/webapps/bid-web/WEB-INF/lib/bid-dao-1.0.jar

              then I would need something like

              Code:
              <import resource="../../spring/dao-context.xml"/>
              This is what I tried and I got..

              FileNotFoundException: /usr/local/apache-tomcat-6.0.29/webapps/bid-web/WEB-INF/classes/spring/../../spring/dao-context.xml (No such file or directory)
              So it would seem that stating relative paths are a bit of an issue here.

              If you do have context files from other modules, how do you reference them? Or do you do a bit of file shuffling while you're making up the war?

              Comment


              • #8
                I got a solution of sorts on the imports. I have used..

                Code:
                <import resource="classpath:spring/dao-context.xml"/>
                as the import in

                /usr/local/apache-tomcat-6.0.29/webapps/bid-web/WEB-INF/classes/spring/web-context.xml
                to get a file in...

                /usr/local/apache-tomcat-6.0.29/webapps/bid-web/WEB-INF/lib/bid-dao-1.0.jar
                and this worked.

                If only I didn't have to name them like this. It kinda fuses the modules together in an unseemly fashion.

                Thanks everyone.

                Comment


                • #9
                  Hi,

                  Can you suggest me the best solution to work with the multipule context files. Where i have similar kind of set up(i.e need to load the diffrent context files extising in sub-projects, all the those sub-project created as jars and placed as part of main web application).


                  Thanks
                  Venakt

                  Comment


                  • #10
                    you can get away with a fixed name for each file (classpath*:/module-config.xml).

                    Comment


                    • #11
                      Originally posted by sentikakar View Post
                      you can get away with a fixed name for each file (classpath*:/module-config.xml).
                      Is it possible to have multiple URL Patterns, with multiple context files, scenario is some thing like this, if context file URL pattern is /test and context2 is /test2, where /test /test2 are two different projects, in this case how to load context files.

                      Thanks
                      Venkat

                      Comment

                      Working...
                      X