CH10. Development and application of Spring framework
Package src.com.qdu.sun.Spring;
Import Org.springframework.beans.factory.BeanFactory;
Import Org.springframework.beans.factory.xml.XmlBeanFactory;
Import Org.springframework.core.io.ClassPathResource;
public class Springtest {
public static void Main (string[] args) {
Beanfactory factory = new Xmlbeanfactory (New Classpathresource ("Applicationcontext.xml"));
HelloWorld GC = (HelloWorld) factory.getbean ("Greetingservice");
Gc.saygreeting ();
}
}
Log4j:warn No Appenders could is found for logger (org.springframework.util.ClassUtils).
Log4j:warn Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException:IOException parsing XML Document from
Class path resource [Applicationcontext.xml]; Nested exception is Java.io.FileNotFoundException:class path resource
[Applicationcontext.xml] cannot is opened because it does not exist
caused By:java.io.FileNotFoundException:class path resource [Applicationcontext.xml] cannot be opened because it does no T exist
At Org.springframework.core.io.ClassPathResource.getInputStream (classpathresource.java:135)
At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( xmlbeandefinitionreader.java:297)
At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( xmlbeandefinitionreader.java:280)
At Org.springframework.beans.factory.xml.xmlbeanfactory.<init> (xmlbeanfactory.java:73)
At Org.springframework.beans.factory.xml.xmlbeanfactory.<init> (xmlbeanfactory.java:61)
At Src.com.qdu.sun.Spring.SpringTest.main (springtest.java:9)
Modified to:
public class Springtest {
public static void Main (string[] args) {
Beanfactory factory = new Xmlbeanfactory (New Classpathresource ("Src/applicationcontext.xml"));
Output:
Log4j:warn No Appenders could is found for logger (org.springframework.util.ClassUtils).
Log4j:warn Please initialize the log4j system properly.
You yi ge Greeting