[ SpringIOC - Champs - Type - Date ]
Bonjour , En fait j'ai un problème sous Spring Ioc avec un champs de Type Date, j'ai pas pu m'en sortir de ce problème
voila la Classe qui Contient le Champs Date
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| package achat.vente;
import java.util.Date;
public class Commande
{
private Long id;
private Date dateCommande;
public Commande() {
super();
// TODO Auto-generated constructor stub
}
public Commande(Date dateCommande, Long id) {
super();
this.dateCommande = dateCommande;
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getDateCommande() {
return dateCommande;
}
public void setDateCommande(Date dateCommande) {
this.dateCommande = dateCommande;
}
public String toString()
{
return "id :" + id.toString() + "Date Commande :" + this.dateCommande;
}
} |
Puis je vous montre le Fichier Config.xml ( fichier Spring)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="beanCommande" class="achat.vente.Commande">
<property name="id">
<value>1</value>
</property>
<property name="dateCommande" >
<value>"05/06/1990"</value>
</property>
</bean>
</beans> |
et voila la Class Test pour tester
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package achat.test;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import achat.vente.Commande;
import junit.framework.TestCase;
public class Test extends TestCase {
private ListableBeanFactory fr;
protected void setUp() throws Exception
{
fr=new XmlBeanFactory(new ClassPathResource("config.xml"));
}
public void test()
{
Commande com=(Commande) fr.getBean("beanCommande");
System.out.println(com.toString());
}
} |
Enfin je vous montre l'erreur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beanCommande' defined in class path resource [config.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'dateCommande']
PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'dateCommande'
at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:1068)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:821)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:734)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:862)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:889)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:878)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:934)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:731)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:340)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at achat.test.Test.test(Test.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) |
Merci bcp de m'aider de ce problème
Et merci d'avance :ccool: