改成下面的BeanFactory factory=new XmlBeanFactory(new InputStreamResource(new InputStream("hello.xml")));
解决方案 »
- 如何防止用户在TextBox中输入Html标签.......
- struts1的问题
- 有没有人熟悉JAAS+GSS-API+Kerberos+LDAP实现SSO
- java 获取客户端所有ip
- 留言怎么按时间排序
- java技术题
- JBPM web designer 怎么保存流程?
- hibernate 查询问题
- HQL 和 SQL 有什么本质的区别呢?谁帮忙写一个例子!!!
- MyBatis问题
- java建模uml的工具常用的有什么呢
- [200分]hibernate映射文件中的cascade和inverse什么怎样配合使用,什么时候该用inverse,什么时候用cascade="all-delete-orphan"呢?
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at linqi.Helloapp.main(Helloapp.java:18)
我用的是Myeclipse生成的spring,它是什么版本的呀?和这个有关系吗??
BeanFactory factory=new XmlBeanFactory(new InputStreamResource(new InputStream("hello.xml")));
它还是报错:不能实例化类型 InputStream,这是因为它不是一个具体类
这怎么解决呀
log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.这是怎么回事!!!!
org.springframework.beans.factory.BeanDefinitionStoreException: Passed-in Resource [resource loaded through InputStream] contains an open stream: cannot determine validation mode automatically. Either pass in a Resource that is able to create fresh streams, or explicitly specify the validationMode on your XmlBeanDefinitionReader instance.
BeanFactory factory = new XmlBeanFactory(new InputStreamResource(new FileInputStream("/hello.xml")));
GreetingService greetingService = (GreetingService) factory.getBean("greetingService");
greetingService.sayGreeting();
} catch (Exception e) {
System.out.println(e);
}
的默认工作路径为项目根路径,也就是.project文件所在的目录,而默认输出目录/bin是项目
CLASSPATH的一部分,并非工作路径。2.把HelloApp.java改成这样:package com.springinaction.chapter01.hello;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;public class HelloApp {
public static void main(String[] args) throws Exception {
try { ApplicationContext ctx = new FileSystemXmlApplicationContext("hello.xml");
GreetingService greetingService = (GreetingService) ctx.getBean("greetingService"); greetingService.sayGreeting();
} catch (Exception e) {
System.out.println(e);
}
}
}包你可以通过编译和运行,运行结果为:Buenos Dias!还有1点,虽然是小问题,但是缺它不可,就是hello.xml中的这段声明:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">缺了它就不能运行很奇怪,呵呵:)