IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Mon premier "Hello World" avec spring [Framework]


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2013
    Messages
    54
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 54
    Par défaut Mon premier "Hello World" avec spring
    Bonjour,

    Je suis encore un très débutant en spring et je veux faire mon premier "Hello World" avec spring mais mon premier exemple ça marche pas,voici donc mes fichiers et classes:

    HelloWorld.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     package com.tutorialspoint;
     
    public class HelloWorld {
    	private String message; 
    	public void setMessage(String message){ 
    	this.message = message; 
    	} 
    	public void getMessage(){ 
    	System.out.println("Your Message : " + message); 
    	}
     
    }
    MainApp.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     package com.tutorialspoint;
    import org.springframework.context.ApplicationContext; 
    import org.springframework.context.support.ClassPathXmlApplicationContext; 
    public class MainApp { 
    public static void main(String[] args) { 
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); 
    HelloWorld obj = (HelloWorld) context.getBean("helloWorld"); 
    obj.getMessage(); 
    }
    }
    Beans.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     <?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.0.xsd">
     <bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
      <property name="message" value="Hello World!"/> 
      </bean> 
      </beans>
    et lors de l’exécution depuis ma classe principale,voici les erreurs que je rencontre:
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    ApplicationContext cannot be resolved to a type
    ClassPathXmlApplicationContext cannot be resolved to a type

    at com.tutorialspoint.MainApp.main(MainApp.java:6)
    Pourriez-vous me dire où est le problème?

  2. #2
    Membre confirmé
    Inscrit en
    Octobre 2005
    Messages
    136
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 136
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    ApplicationContext cannot be resolved to a type
    ClassPathXmlApplicationContext cannot be resolved to a type
    Il te manque sans doute les librairies de Spring.

  3. #3
    Membre averti
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2013
    Messages
    54
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 54
    Par défaut
    Non j'ai déjà installé ces librairies:
    antlr-runtime-3.0.1
    org.springframework.aop-3.1.0.M2
    org.springframework.asm-3.1.0.M2
    org.springframework.aspects-3.1.0.M2
    org.springframework.beans-3.1.0.M2
    org.springframework.context.support-3.1.0.M2
    org.springframework.context-3.1.0.M2
    org.springframework.core-3.1.0.M2
    org.springframework.expression-3.1.0.M2
    commons-logging-1.1.1

  4. #4
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    salut, j´ai exactement pris ton code, et tes librairies et sans rien changer, voici le resultat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Jul 27, 2013 8:56:45 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5d79a4c9: startup date [Sat Jul 27 08:56:45 CEST 2013]; root of context hierarchy
    Jul 27, 2013 8:56:45 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [Beans.xml]
    Jul 27, 2013 8:56:46 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2a41da1c: defining beans [helloWorld]; root of factory hierarchy
    Your Message : Hello World!

  5. #5
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    Voici la structure de mon Projet voir fichier attaché.
    Images attachées Images attachées  

  6. #6
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,

    Ouvre le fichier avec un archiveur et vérifie le chemin s'il a la class org.springframework.context.support.ClassPathXmlApplicationContext compilé mais pas celui de la code source .java ou que le fichier Jar n'est pas tronqué.

    A+.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Visual Web] Mon premier Hello world avec netbeans
    Par programaniac dans le forum NetBeans
    Réponses: 10
    Dernier message: 09/04/2009, 06h24
  2. Premier développement de services web avec Spring-WS
    Par Arnaud_03 dans le forum Services Web
    Réponses: 5
    Dernier message: 02/12/2008, 16h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo