Configuração Spring 2.0 - Failed to convert property value o

0 respostas
R

Boa tarde a todos.

Desculpem se já existir um tópico sobre o mesmo problema, mas, por não saber o que o causa, creio que não estou nem sabendo pesquisar a solução (visto que nem no google consigo achar :lol: falta direção mesmo...)

Bom, mas, vamos lá: Estou brincando numa aplicação aqui, com Spring 2.0, e Hibernate, server Jboss 4.0.5, uso Eclipse 3.2. Para me enturmar bem com o Spring, estou seguindo alguns tutoriais, e por enquanto fazendo toda a configuração via XML (depois q aprender, passo para anotações, hehehe).

Como um arquivo XML para todas as configurações fica extremamente complicado de mexer, separei em:

action-servlet: o principal, que declara os controladores, e faz as outras configurações básicas;
applicationContext-service.xml: declaração dos services
applicationContext-jdbc.xml: configurações do banco;
applicationContext-dao.xml: configurações do hibernate e meus daos

Meu arquivo applicationContext-dao.xml está da seguinte forma:
<?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="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

		<property name="dataSource">
			<ref bean="dataSource"/>
		</property>
	
		<property name="configLocation">
			<value>WEB-INF/hibernate.cfg.xml</value>
		</property>
	
		<property name="configurationClass">
			<value>org.hibernate.cfg.AnnotationConfiguration</value>
		</property>
	
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
			</props>
		</property>
	</bean>

	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
		<ref bean="sessionFactory"/>
		</property>
	</bean>

	<bean id="txAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">

	<property name="properties">
		<props>
			<prop key="add*">PROPAGATION_REQUIRED</prop>
			<prop key="update*">PROPAGATION_REQUIRED</prop>
			<prop key="remove*">PROPAGATION_REQUIRED</prop>
			<prop key="send*">PROPAGATION_REQUIRED</prop>
		</props>
	</property>
</bean>

	<bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager">
			<ref local="transactionManager"/>
		</property>
	
		<property name="transactionAttributeSource">
			<ref local="txAttributeSource"/>
		</property>
	</bean>

	<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="interceptorNames">
			<list>
				<idref local="txInterceptor"/>
			</list>
		</property>
		<property name="beanNames">
			<list>
				<value>*Dao</value>
				<value>*DAO</value>
			</list>
		</property>
	</bean>

	<bean id="usuarioDAO" class="br.com.test.dao.UsuarioDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory"/>
		</property>
	</bean>
</beans>
E, no applicationContext-service.xml faço a referência pra o bean do meu DAO:
...
<bean id="usuarioService" parent="txProxyTemplate">
		<property name="target">
			<bean class="br.com.test.services.UsuarioService">
				<property name="usuarioDAO">
					<ref bean="usuarioDAO"/>
				</property>
			</bean>
		</property>
	</bean>...

Mas, no console tenho o seguinte erro:

15:29:57,015 INFO  [SessionFactoryImpl] closing
15:29:57,015 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usuarioService' defined in ServletContext resource [/WEB-INF/applicationContext-service.xml]: Cannot create inner bean 'br.com.test.services.UsuarioService#15998cb' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.test.services.UsuarioService#15998cb' defined in ServletContext resource [/WEB-INF/applicationContext-service.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy64] to required type [br.com.test.dao.UsuarioDAO] for property 'usuarioDAO'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
Caused by: 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.test.services.UsuarioService#15998cb' defined in ServletContext resource [/WEB-INF/applicationContext-service.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy64] to required type [br.com.test.dao.UsuarioDAO] for property 'usuarioDAO'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
Caused by: 
org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessException details (1) are:
PropertyAccessException 1:
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy64] to required type [br.com.test.dao.UsuarioDAO] for property 'usuarioDAO'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
Caused by: 
java.lang.IllegalArgumentException: No matching editors or conversion strategy found
	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:212)
	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:127)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:775)

E, não sei o que significa esse erro... não sei qual configuração está exatamente causando-o. Se eu mudar o id do bean para qualquer coisa, "testeDeBEan", por exemplo, tanto no xml do DAO quanto do service, a inicialização funciona corretamente. Mas, se volto para usuarioDAO, pára de funcionar. Por que isso ocorre? Não pode ter o mesmo nome da classe? Assim, no service, tenho a variável:

private UsuarioDAO usuarioDAO;
	
	public void setUsuarioDAO(UsuarioDAO usuarioDAO) {
		this.usuarioDAO = usuarioDAO;
	}

Não sei se fui clara, se precisar de mais alguma informação é só me falar.

Obrigada.

Criado 10 de março de 2007
Respostas 0
Participantes 1