run jar java-jar xxx.jar not find the jar package spring configuration file
Here is the project structure:
I can confirm labeled jar files no problem, applicationContext in the root directory
startup main method:
public static void main(String[] args) {
ApplicationContext context =new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml","task.xml"});
}
After running error:
hy
[2013-07-24 09:55:23,864 INFO at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:315)] Loading XML bean definitions from class path resource [applicationContext.xml]
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [applicationContext.xml]
seeking a solution, how to find the configuration file it, Chedan do not answer.
------ Solution --------------- -----------------------------
Hello, I also found this problem, go online to search a bit, try the If you are a project directly call the jar package (classPath same), then use the following:
ApplicationContext context = new ClassPathXmlApplicationContext ("classpath *: config / appContext.xml");
which loads the file in the classpath, but this load is not intuitive, because even find the file, spring is not an error, just return the applicationContext no content, which can be read directly into
- ---- For reference only ---------------------------------------
I by which nobody ..
------ For reference only ----------------------------- ----------
jar included in the category by the following method to get the configuration file path or load the configuration file, the principle is the class at runtime through classLoader access to resources
URL fileURL = this.getClass (). getResource ("/ config / application.xml") ;/ / jar jar package in the class to get the resource file path
InputStream is = this.getClass (). getResourceAsStream ("/ config / application.xml") ;/ / jar jar in the class read the package resource file
---- - For reference only ---------------------------------------
Boss, I load the spring it can be so loaded it
------ For reference only -------------------------- -------------
loaded spring if not the default directory, it must specify the file path, the total can not spring traverse the entire jar xml files inside it
------ For reference only ---------------------------------------
I specified is the root directory, how could traverse, ......
trouble you know spring ClassPathXmlApplicationContext how loaded again for the right
also trouble you look at how I said I was loaded.
------ For reference only -------------------- -------------------
did not look carefully, with a ditch by 1L
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
xml contents of the file in question, the opening lines posted about it
may http://www.springframework.org/schema/context relevant content can be deleted
------ For reference only ------------ ---------------------------
sure no problem, you can run, and lead into the jar after the die is
------ For reference only ------------------------------------- -
long time did not play jar package, have forgotten this stubble,
common method used to get the configuration file should be placed outside the jar.
in the jar inside, one is analytic jar files, one is the kind of 2L.
------ For reference only -------------------------------------- -
ClassPathXmlApplicationContext This class can only be read on web-info/classes directory configuration file, you see your card this directory there is no such thing to say.
------ For reference only -------------------------------------- -
not a web project, how will web-info
say if it is web project, why labeled jar package, directly on the war package
------ For reference only ---------------- -----------------------
That how it can be placed on the outer jar?
------ For reference only ---------------------------------- -----
just the same jar file directory
------ For reference only ------------------------ ---------------
own good to learn ClassPathXmlApplicationContext load path of this class.
------ For reference only -------------------------------------- -
you pretend to understand this word in addition to my little XX send you a
------ For reference only ----------- ----------------------------
this classpath classpath * I have have also tried to get any
but I did not this layer conf directory in the root directory of my
I also read online that, but I see I made the directory structure diagram, maven structure so I do not have this level directory conf
------ For reference only ---------------------------------- -----
you pretend to understand this word in addition to my little send you XX Okay, you win. Sucker
------ For reference only ------------------------------------- -
wrote a few items to think that they know everything, but also to understand here to ask your sister ah, someone kindly give you the answer, you XX, xx your sister ah.
------ For reference only -------------------------------------- -
find it very surprising if the jar package into other works carried out under load and when I said that the method can be run (personally tried), you can create a new project, put the jar package lay up, with code calls can be executed correctly, but if it is an executable / or calls will be executed when the case file is not found, there is no way I can change the properties of the form, and if there is time to study, it may be code issues . But I think spring as such a mature framework, should develop a Resource or inputStream type can be used for input ApplicationContext, doing things like this before without a head, no thread after a bit frustrating. . .
------ For reference only -------------------------------------- -
SB, do not know do not answer questions, OK? watching you this person upset
------ For reference only ------------ ---------------------------
really like that, I do not understand a bit eh ...
------ For reference only -------------------------------------- -
SB, do not know do not answer questions, OK? watching you upset this person I went next door to you Mary
------ For reference only ----------------------------- ----------
new ClassPathXmlApplicationContext (new String [] {xx your sister. xml}) is taken from the web-info/classes, waste things.
------ For reference only -------------------------------------- -
you are such a person is like a mad dog, others give you the bones to eat, you have anti-mouth bite. Upstairs a few people reply to you run, you attitude is very bad, someone else to help you, but not your sister xx, you bad what? Really understand their own, but also come up with such a simple question to ask a ball? Ungrateful waste one, say one, I went next door to you Mary.
------ For reference only -------------------------------------- -
you figure out what is called the classpath say it
------ For reference only ---------------------- -----------------
you figure out what is called the classpath to say it I see you do not understand a sucker waste
没有评论:
发表评论