je débute à peine à m'interesser à spring, comment l'utiliser? si j ajoute le fichier spring.jar à la librairie d'eclipse je pourrai travailler avec spring? c'est suffisant?
Version imprimable
je débute à peine à m'interesser à spring, comment l'utiliser? si j ajoute le fichier spring.jar à la librairie d'eclipse je pourrai travailler avec spring? c'est suffisant?
Pour l'utiliser, ça fonctionne comme n'importe quelle autre bibliothèque, tu inclues les dépendances au projet (donc au moins spring.jar puis tout ce que tu as besoin d'autre) et tu peux travailler avec
J'obtient l erreur:
The constructeur XmlBeanFactory(FileInputStream) is undefined
Ce qui est vrai (cf la doc de XmlBeanFactory)
Il faut utiliser une implémentation de l'interface Resource comme argument pour le constructeur
Dans ton cas, la classe InputStreamResource pourrait convenir
excuse moi je comprend pas tres bien ce que tu dis! tu peux éclairer stp
Si je reprends ton code depuis l'autre topic, tu fais donc ceci:
Or il n'est pas possible de créer une instance de la classe XmlFactoryBean avec un FilInputStream en paramètre, il faut obligatoirement un objet de type Resource.Code:BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));
Comme tu utilises un FileInputStream, je suppose que ce qui te conviendrait le mieux est une Resource de type InputStreamResource, exemple:
Code:
1
2
3
4 InputStream inputStream = new FileInputStream("hello.xml"); Resource resource = new InputStreamResource(inputStream); BeanFactory factory = new XmlBeanFacory(resource);
et pour les import? car j' ai encore des erreurs
voila ma classe:
import java.io.FileInputStream;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.*;
public class HelloApp {
public static void main(String[] args) throws Exception {
InputStream inputStream = new FileInputStream("hello.xml");
Resource resource = new InputStreamResource(inputStream);
BeanFactory factory = new XmlBeanFactory(resource);
GreetingService greetingService = (GreetingService) factory.getBean("greetingService");
greetingService.sayGreeting();
}
}
Essaie de prendre l'habitude de mettre le message d'erreur, sinon c'est très difficile de t'aider :)
Ceci dit, je suppose qu'il ne trouve pas hello.xml c'est ça?
(n'oublie pas le message d'erreur surtout ^^ )
j ai deux erreurs:
InputStream cannot be resolved to a type( ligne 7)
Multiple markers at this line:(ligne 8)
-InputStreamResource cannot be resolved to a type
-Resource cannot be resolved to a type
Code:
1
2
3
4
5
6
7 import java.io.FileInputStream; import java.io.InputStream; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource;
Code:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Code:
1
2
3
4
5
6
7 at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:94) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:109) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:118) at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:87) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:72) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61) at HelloApp.main(HelloApp.java:15)
Il faut inclure common-logging.jar à ton projet, tu le trouves dans les dépendences de spring (répertoire lib\jakarta-commons)Citation:
Envoyé par mkachakh
PS: Pas la peine de m'envoyer de MP, écris plutôt sur le forum pour que tout le monde puisse voir, et de toute façon ça ne me fait pas venir plus vite :)
ca marche, merci