aspose file tools*
The moose likes Spring and the fly likes Reading applicationContext file from META-INF in spring apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Reading applicationContext file from META-INF in spring apps" Watch "Reading applicationContext file from META-INF in spring apps" New topic
Author

Reading applicationContext file from META-INF in spring apps

mozammil muzza
Ranch Hand

Joined: Dec 22, 2011
Posts: 32

Hi ALL,

I am trying to read applicationContext file from META-INF because i am creating the jar of my project APIs.
When i am trying to read it in my project(simple java project) normally e.g. in resource/applicationContext.xml then able to read it fine and loads successfully.
But once i create the lib of it and putting this spring context file in META-INF then its not reading the file...
i tried
ClassPathXMLApplicationContext("META-INF/applicationContext.xml")
and also
getClass().getClassLoader().getResourceAsStream("META-INF/applicationContext.xml")
.
But not able to create the bean, which i am able to read, load and create normally...

Please provide me proper solution of it.

Thanks...


Khuda Haafiz Muzza 4 Java
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Not sure I am following you. In your jar project you would put the config XML in src/main/resources. Then you are building that jar. Now you are including that jar as a dependency in another jar. Where is the META-INF stuff coming from? If both your projects have their own configs in src/main/resources and they have the same name i.e. applicationContext.xml you need to do something like this


This special prefix specifies that all classpath resources that match the given name must be obtained


[How To Ask Questions][Read before you PM me]
mozammil muzza
Ranch Hand

Joined: Dec 22, 2011
Posts: 32

Thanks 4 your reply Bill,

Actually when i am creating the archive(jar) of my classes (ofcourse it i'll have META-INF) at that time i am putting this config (xml etc.) file from /resource/.. to META-INF folder of the jar.
But but not able to read it from META-INF folder.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

What I don't understand is why you are moving it. The classpath: prefix will look inside jars.
mozammil muzza
Ranch Hand

Joined: Dec 22, 2011
Posts: 32

What I don't understand is why you are moving it. The classpath: prefix will look inside jars.


can you please tell me where exactly i have to use this...when i create the library of my apis or before i.e. when i am developing it in eclipse or will it work in both the scenarios ?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Should work in both.

You have in JAR1

src/main/resources/jar1-application-context.xml


You have in JAR2
src/main/resources/jar2-application-context-xml



Now JAR2 has a dependency on JAR1. JAR1 is on the classpath. When I start JAR2

mozammil muzza
Ranch Hand

Joined: Dec 22, 2011
Posts: 32

I tried this but not working, its giving exception on reading the file.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

What kind of exception? If its a file not found then that means the jar is not on the classpath.
 
Don't get me started about those stupid light bulbs.
 
subject: Reading applicationContext file from META-INF in spring apps