2014-06-27 6 views
0

Je veux étudier si printemps, je commence de Bonjour tout le mondeErreur lors de l'appel ClassPathResource.getInputStream()

J'ai appris à faire un monde bonjour de cette adresse « http://javacpplus.blogspot.com/2012/04/spring-framework-with-netbeans-70.html[url=http://http://javacpplus.blogspot.com/2012/04/spring-framework-with-netbeans-70.html]webpage[/url] »

Et voici mon code, je fais deux classes. 1 Et 2 HelloWorld.java MainApp.java et je fais un xml qui est beans.xml

vérifier est hors classe HelloWorld.java

package com.hello; 

/** * * @author bobfuad */ public class HelloWorld { 
    private String message; 

    public void setMessage(String message){ 
     this.message = message; } 

    public void getMessage(){ 
     System.out.println("Your Message : " + message); } } 

classe MainApp.java

package com.hello; 

mport org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
/** 
* 
* @author bobfuad 
*/ 
public class MainApp { 
    private static Resource ClassPathApplicationContext; 
    public static void main(String[] args) { 
     ApplicationContext context; 
     context = new ClassPathXmlApplicationContext("Beans.xml"); 

     HelloWorld obj = (HelloWorld) context.getBean("helloWorld"); 

     obj.getMessage(); 
    } 
} 

beans.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
"> 
<bean id="helloWorld" class="com.hello.HelloWorld"> 
     <property name="message" value="Hello World!"/> 
    </bean> 
</beans> 

que c'est mon code, mais quand je lance ce programme, il y a avoir des problèmes

ce qui est le problème

Jun 27, 2014 8:48:44 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh 
INFO: Refreshing org[email protected]e3849c: startup date [Fri Jun 27 08:48:44 PDT 2014]; root of context hierarchy 
Jun 27, 2014 8:48:44 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from class path resource [Beans.xml] 
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [Beans.xml] cannot be opened because it does not exist 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243) 
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127) 
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93) 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
    at com.hello.MainApp.main(MainApp.java:18) 
Caused by: java.io.FileNotFoundException: class path resource [Beans.xml] cannot be opened because it does not exist 
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) 
    ... 13 more 
Java Result: 1 
BUILD SUCCESSFUL (total time: 0 seconds) 

s'il vous plaît aidez-moi, merci

+0

S'il vous plaît fournir un titre plus utile – Coffee

Répondre

0

Comme le message d'erreur dit, beans.xml ne se trouve pas dans votre classpath (en le chemin donné, c'est-à-dire la racine). Si vous avez placé le fichier à côté des classes Java au com/hello, utilisez le chemin com/hello/Beans.xml dans votre méthode principale.