Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to load context files

  1. #1
    Join Date
    Jul 2008
    Posts
    28

    Default 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
    Attached Files Attached Files
    Last edited by largesnike; Jan 13th, 2011 at 12:38 AM. Reason: bad title

  2. #2
    Join Date
    Nov 2010
    Posts
    11

    Default

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

  3. #3
    Join Date
    Jul 2008
    Posts
    28

    Default

    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.

  4. #4
    Join Date
    Nov 2005
    Posts
    113

    Default

    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

  5. #5
    Join Date
    Jul 2008
    Posts
    28

    Default

    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?

  6. #6

    Default

    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

  7. #7
    Join Date
    Jul 2008
    Posts
    28

    Default

    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?

  8. #8
    Join Date
    Jul 2008
    Posts
    28

    Default

    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.

  9. #9
    Join Date
    Nov 2012
    Posts
    3

    Default

    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

  10. #10

    Default

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

Posting Permissions

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