E:\java web work\spring\com\springinaction\chapter01\hello\HelloApp.java:11: cannot resolve symbol symbol : class Resource location: class com.springinaction.chapter01.hello.HelloApp Resource resource=new ClassPathResource("hello.xml"); ^ E:\java web work\spring\com\springinaction\chapter01\hello\HelloApp.java:11: cannot resolve symbol symbol : class ClassPathResource location: class com.springinaction.chapter01.hello.HelloApp Resource resource=new ClassPathResource("hello.xml"); ^ 2 errors工具以退出代码 1 完成
加上了 import org.springframework.core.io.ClassPathResource; 一样出错,请再帮我谢谢! E:\java web work\spring\com\springinaction\chapter01\hello\HelloApp.java:12: cannot resolve symbol symbol : class Resource location: class com.springinaction.chapter01.hello.HelloApp Resource resource=new ClassPathResource("hello.xml"); ^ 1 error工具以退出代码 1 完成
编译通过了,但是运行时出错log4j:WARN No appenders could be found for logger (org.springframework.core.Coll ectionFactory). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStore Exception: IOException parsing XML document from class path resource [hello.xml] ; nested exception is java.io.FileNotFoundException: class path resource [hello. xml] cannot be opened because it does not exist java.io.FileNotFoundException: class path resource [hello.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat hResource.java:137) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea nDefinitions(XmlBeanDefinitionReader.java:167) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea nDefinitions(XmlBeanDefinitionReader.java:148) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFa ctory.java:73) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFa ctory.java:61) at com.springinaction.chapter01.hello.HelloApp.main(HelloApp.java:15)
Resource resource=new ClassPathResource("hello.xml");
BeanFactory factory=new XmlBeanFactory(resource);
//BeanFactory factory=new XmlBeanFactory(new FileInputStream("hello.xml"));
GreetingService greetingService=(GreetingService)factory.getBean("greetingService");
greetingService.sayGreeting();但是还是出错了:
package com.springinaction.chapter01.hello;import java.io.FileInputStream;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;public class HelloApp
{
public static void main(String[] arg) throws Exception
{
Resource resource=new ClassPathResource("hello.xml");
BeanFactory factory=new XmlBeanFactory(resource);
//BeanFactory factory=new XmlBeanFactory(new FileInputStream("hello.xml"));
GreetingService greetingService=(GreetingService)factory.getBean("greetingService");
greetingService.sayGreeting();
}
}怎麽办~~~~
symbol : class Resource
location: class com.springinaction.chapter01.hello.HelloApp
Resource resource=new ClassPathResource("hello.xml");
^
E:\java web work\spring\com\springinaction\chapter01\hello\HelloApp.java:11: cannot resolve symbol
symbol : class ClassPathResource
location: class com.springinaction.chapter01.hello.HelloApp
Resource resource=new ClassPathResource("hello.xml");
^
2 errors工具以退出代码 1 完成
如果是初学的,不要去搞什么spring,看看基础为好
import org.springframework.core.io.ClassPathResource;
一样出错,请再帮我谢谢!
E:\java web work\spring\com\springinaction\chapter01\hello\HelloApp.java:12: cannot resolve symbol
symbol : class Resource
location: class com.springinaction.chapter01.hello.HelloApp
Resource resource=new ClassPathResource("hello.xml");
^
1 error工具以退出代码 1 完成
Resource resource=new ClassPathResource("hello.xml");也可能无法查找到hello.xml,因为不在不在classPath路径中.
import org.springframework.core.io.Resource;
ectionFactory).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStore
Exception: IOException parsing XML document from class path resource [hello.xml]
; nested exception is java.io.FileNotFoundException: class path resource [hello.
xml] cannot be opened because it does not exist
java.io.FileNotFoundException: class path resource [hello.xml] cannot be opened
because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat
hResource.java:137)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:167)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:148)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFa
ctory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFa
ctory.java:61)
at com.springinaction.chapter01.hello.HelloApp.main(HelloApp.java:15)
比如C:\\test\\hello.xml