Problema com Spring: NotWritablePropertyException

0 respostas
Marcelo_FS

Bem pessoal, estou mudando o servidor de aplicação do Tomcat para o JBoss. No Tomcat o sistema funcionava normalmente… o erro que está ocorrendo é esse:

11:36:11,718 ERROR [ContextLoader] Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'relatorioColetasDelegate' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'relatorioColetasDelegateTarget' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'relatorioColetasBusiness' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'coletaAgendaDAO' of bean class [business.relatorio.impl.RelatorioColetasBusiness]: Bean property 'coletaAgendaDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'relatorioColetasBusiness' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'coletaAgendaDAO' of bean class [business.relatorio.impl.RelatorioColetasBusiness]: Bean property 'coletaAgendaDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'coletaAgendaDAO' of bean class [business.relatorio.impl.RelatorioColetasBusiness]: Bean property 'coletaAgendaDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:751) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:608) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:74) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57) at ...

Pois bem, eu fui na RelatorioColetasBusiness. O método getColetaAgendaDAO não existe, então eu criei ele, mas mesmo assim não funciona. Segue a parte relevante do código
(notem que existem atributos que funcionam sem o método get):

public class RelatorioColetasBusiness implements IRelatorioColetasBusiness {

	private IManterColetaDAO coletaDAO;	
	private IManterColetaAgendaDAO coletaAgendaDAO;

	public void setColetaDAO(IManterColetaDAO coletaDAO) {
		this.coletaDAO = coletaDAO;
	}
	
	public void setColetaAgendaDAO(IManterColetaAgendaDAO coletaAgendaDAO) {
		this.coletaAgendaDAO = coletaAgendaDAO;
	}

//	public void getColetaAgendaDAO() {
//		return this.coletaAgendaDAO;
//	}
}
public abstract class ADaoSpring extends HibernateDaoSupport { ... }

public interface IManterColetaAgendaDAO { ... }
  -- public class ManterColetaAgendaDAO extends ADaoSpring implements IManterColetaAgendaDAO { ... }

public interface IManterColetaDAO { ... }
  -- public class ManterColetaDAO extends ADaoSpring implements IManterColetaDAO{ ... }

Meu applicationContext.xml está mapeado assim:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans default-autowire="byName">
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		...
    </bean>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
                ...
    </bean>
    <!-- Mapeamentos do hibernate -->
                ...
    <!-- /Mapeamentos do hibernate -->

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

    <bean id="coletaAgendaDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
	<property name="target">
            <ref local="objAManterColetaAgendaDAO"/>
	</property>
        <property name="preInterceptors">
            <list>
                <ref bean="wbsaInterceptador"/>
            </list>
        </property>

        <property name="transactionManager">
            <ref bean="transactionManager"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
            </props>
        </property>
    </bean>

    <bean id="relatorioColetasBusiness" class="business.relatorio.impl.RelatorioColetasBusiness" singleton="true" autowire="no">
        <property name="coletaDAO">
            <ref local="objAManterColetaDAO"/>
        </property>
        <property name="coletaAgendaDAO">
            <ref local="objAManterColetaAgendaDAO"/>
        </property>			
    </bean>

    <bean id="objAManterColetaDAO" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="target">
            <ref bean="manterColetaDAOTarget"/>
        </property>
        <property name="proxyInterfaces">
            <value>persistence.dao.interfaces.IManterColetaDAO</value>
        </property>
        <property name="interceptorNames">
            <list>
                <value>hibernateInterceptor</value>
            </list>
        </property>
    </bean>

    <bean id="objAManterColetaAgendaDAO" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="target">
            <ref bean="manterColetaAgendaDAOTarget"/>
        </property>
        <property name="proxyInterfaces">
            <value>persistence.dao.interfaces.IManterColetaAgendaDAO</value>
        </property>
        <property name="interceptorNames">
            <list>
                <value>hibernateInterceptor</value>
            </list>
        </property>
    </bean>
    <bean id="manterColetaDAOTarget" class="persistence.dao.ManterColetaDAO" singleton="true"/>
    <bean id="manterColetaAgendaDAOTarget" class="persistence.dao.ManterColetaAgendaDAO" singleton="true"/>

Pelo que eu (pouco) entendo do Spring, o código aparenta estar certo… pelo menos de acordo com o que a Exception dá de mensagem!! Procurei em outros fóruns/google/etc e geralmente o pessoal sugere pra verificar se o nome da propriedade no bean bate com o nome no .xml… acredito que esteja certo isso também…

Alguém tem alguma (qualquer) sugestão do que eu posso testar a seguir? Já perdi uma manhã nisso… ):

Criado 1 de julho de 2008
Respostas 0
Participantes 1