Hi everyone. I've already searched on the forum for a post on this, but with no luck (sadly). So I'll ask you guys how to handle it.
I have a service bean, that have to be injected with a dao. This is pretty much common task, but I'm trying to inject a proxy dao (derived from Per Mellqvist article Don't repeat the Dao) in my business layer, and it keeps running with the same Exception - java.lang.ClassCastException: org.springframework.beans.factory.config.FieldRetr ievingFactoryBean
All my dao tests runs pretty much fine, but now I'm trying to run service tests, and is throwing this exception.
Here's my code:
serviceContext.xml
serviceBeans.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <aop:config> <aop:advisor id="serviceTx" advice-ref="txAdvice" pointcut="execution(* *..service.*Service.*(..))"/> </aop:config> <tx:annotation-driven/> <aop:aspectj-autoproxy /> <tx:advice id="txAdvice"> <tx:attributes> <tx:method name="*"/> </tx:attributes> </tx:advice> </beans>
daoBeans.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <tx:advice id="UfTxAdvice"> <tx:attributes> <tx:method name="persist" rollback-for="ServiceException" /> <tx:method name="detach" rollback-for="ServiceException" /> </tx:attributes> </tx:advice> <bean id="ufService" class="com.controlfarma.service.impl.UfServiceImpl"> <constructor-arg> <idref bean="ufDao"/> </constructor-arg> </bean> </beans>
Manageable.javaCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="ufDao" parent="abstractDao"> <property name="proxyInterfaces" value="com.controlfarma.dao.UfDao" /> <property name="target"> <bean parent="abstractDaoTarget"> <constructor-arg value="com.controlfarma.model.Uf" /> </bean> </property> </bean> </beans>
ServiceImpl.javaCode:package net.dev.java.jnovice.service; import java.io.Serializable; import java.util.List; import net.dev.java.jnovice.service.exception.ServiceException; public interface Manageable<Entity> extends Serializable { void persist(Entity entity) throws ServiceException; void detach(Serializable... pks) throws ServiceException; List<Entity> filterBy(Entity e); Entity retrieve(Serializable pk); }
UfService.javaCode:package net.dev.java.jnovice.service.impl; import java.io.Serializable; import java.util.List; import net.dev.java.jnovice.dao.Persistable; import net.dev.java.jnovice.service.Manageable; import net.dev.java.jnovice.service.exception.ServiceException; public class ServiceImpl<Entity> implements Manageable<Entity> { private static final long serialVersionUID = -7161460115421961298L; private Persistable<Entity> dao; public ServiceImpl() { } public void detach(Serializable... pks) throws ServiceException { try { for (Serializable pk : pks) { dao.makeTransient(pk); } } catch (Exception e) { throw new ServiceException(); } } public void persist(Entity entity) throws ServiceException { try { dao.makePersistent(entity); } catch (Exception e) { throw new ServiceException(); } } public Entity retrieve(Serializable pk) { return dao.doRetrieve(pk); } @SuppressWarnings("unchecked") public List<Entity> filterBy(Entity e) { return dao.filterBy(e); } public Persistable<Entity> getDao() { return dao; } public void setDao(Persistable<Entity> dao) { this.dao = dao; } }
UfServiceImpl.javaCode:package com.controlfarma.service; import java.util.List; import com.controlfarma.model.Uf; import net.dev.java.jnovice.service.Manageable; public interface UfService extends Manageable<Uf> { public static final String SPRING_NAME = "ufService"; public List<Uf> searchByAll(); public List<Uf> searchByNomeLike(String nome); public List<Uf> searchBySiglaExact(String sigla); public List<Uf> searchByNomeLikeAndSiglaExact(String nome, String sigla); public List<Object[]> scalarByAll(); public List<Object[]> scalarByNomeLike(String nome); public List<Object[]> scalarBySiglaExact(String sigla); public List<Object[]> scalarByNomeLikeAndSiglaExact(String nome, String sigla); public List<Uf> filterBy(Uf filter); }
Thanks in advance and best regardsCode:package com.controlfarma.service.impl; import java.util.List; import net.dev.java.jnovice.service.impl.ServiceImpl; import com.controlfarma.dao.UfDao; import com.controlfarma.model.Uf; import com.controlfarma.service.UfService; @SuppressWarnings("serial") public class UfServiceImpl extends ServiceImpl<Uf> implements UfService { public UfServiceImpl(UfDao dao) { this.setDao(dao); } public List<Uf> filterBy(Uf filter) { return getDao().filterBy(filter); } public List<Object[]> scalarByAll() { UfDao dao = (UfDao) getDao(); return dao.scalarByAll(); } public List<Object[]> scalarByNomeLike(String nome) { UfDao dao = (UfDao) getDao(); return dao.scalarByNomeLike(nome); } public List<Object[]> scalarByNomeLikeAndSiglaExact(String nome, String sigla) { UfDao dao = (UfDao) getDao(); return dao.scalarByNomeLikeAndSiglaExact(nome, sigla); } public List<Object[]> scalarBySiglaExact(String sigla) { UfDao dao = (UfDao) getDao(); return dao.scalarBySiglaExact(sigla); } public List<Uf> searchByAll() { UfDao dao = (UfDao) getDao(); return dao.searchByAll(); } public List<Uf> searchByNomeLike(String nome) { UfDao dao = (UfDao) getDao(); return dao.searchByNomeLike(nome); } public List<Uf> searchByNomeLikeAndSiglaExact(String nome, String sigla) { UfDao dao = (UfDao) getDao(); return dao.searchByNomeLikeAndSiglaExact(nome, sigla); } public List<Uf> searchBySiglaExact(String sigla) { UfDao dao = (UfDao) getDao(); return dao.searchBySiglaExact(sigla); } }
Rafael Mauricio Nami


Reply With Quote
. URRAY!!!!!!