Uma luz no spring... CustomDateEditor!

fala galera… blz?
estou aprendendo sobre spring… ou melhor… tentando… ehhehe
e fui tenta usar um CustomDateEditor para setar em uma variavel minha q recebe java.util.Date um valor passado como String… no meu arquivo XML do spring defini ele assim…

<?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="greetingService"
			class="com.springinaction.chapter01.hello.impl.GreetingServiceImpl"
			init-method="init" destroy-method="destroy">
		<constructor-arg>
			<value>Deu certo!?</value>
		</constructor-arg>
		
		<property name="greeting">
			<value>E ae prego!</value>
		</property>
		
		<property name="date2">
			<value>1982-09-15</value>
		</property>
	</bean>
	
	
	<bean id="customEditorConfigurer"
			class="org.springframework.beans.factory.config.CustomEditorConfigurer">
		<property name="customEditors">
			<map>
				<entry key="java.util.Date">
					<bean class="org.springframework.beans.propertyeditors.CustomDateEditor" >
						<constructor-arg>
							<bean class="java.text.SimpleDateFormat">
								<constructor-arg type="java.lang.String">
									<value>yyyy-MM-dd</value>
								</constructor-arg>
							</bean>
						</constructor-arg>
						<constructor-arg type="boolean">
							<value>true</value>
						</constructor-arg>
					</bean>
				</entry>
			</map>
		</property>
	</bean>
	
</beans>

mas qdo executo minha classe de teste… ele lance o seguinte erro…

Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘greetingService’ defined in file [C:\leco\eclipse\workspace\Spring\hello.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 ‘date2’]
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 ‘date2’
at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:951)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:692)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:572)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:737)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:764)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:753)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1061)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
at com.springinaction.chapter01.hello.HelloApp.main(HelloApp.java:19)

alguem tem alguma luz de onde eu esteja errando!? :assusta:

desde jah agradeço a ajuda de todos… :!:

A sessão 2.2.4 do Sping In Action é justamente sobre esse assunto.
Pode ser besteira mas você já inverter a ordem dos beans no arquivo?

então kra… foi justamente neste tópico q me incentivo a fazer esse exemplo bobo para ver como funcionava com datas…

tentei inverter tb no arquivo XML mas naum rolou… :thumbdown:

falaaa galera…

depois de mto pensa… veio a tão esperada luz!! :smiley:

foi um erro na classe de teste… como era um teste antigo… qdo começei a usar spring… na classe de teste eu criava um BeanFactory e naum um ApplicationContext!!! :oops:

huauhauhahuauh

agoraaa tudo solucionado e funfando!
valeu a ajuda de todos! :wink: