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?