Hello,
I have gone through several threads and all of them mention that i need to use Cglib and this error
will go away.Code:java.lang.ClassCastException: $Proxy20 cannot be cast
I think I have done that but still i seem to keep getting the error.
I would appreciate if some one could help me out
service layer
Code:<!-- Activates annotation-based bean configuration --> <context:annotation-config/> <!-- Scans for application @Components to deploy --> <context:component-scan base-package="com.netmemex.netmx" /> <!-- Activate annotated task threads --> <task:annotation-driven executor="executorWithPoolSizeRange"/> <task:executor id="executorWithPoolSizeRange" pool-size="5-25" queue-capacity="5"/> <bean id="serviceFactory" class="org.springframework.beans.factory.config.ServiceLocatorFactoryBean"> <property name="serviceLocatorInterface" value="com.netmemex.netmx.service.transactions.ComplexDuesProcessingServiceFactory"/> </bean> .... <aop:aspectj-autoproxy proxy-target-class="true"/> <aop:config> <aop:pointcut id="serviceOperation" expression="execution(* com.netmemex.netmx.service.impl.*Service*.*(..))"/> <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/> </aop:config> ... <aop:config proxy-target-class="true"> <aop:aspect ref="encryptAspect"> <aop:pointcut id="encryptTransaction" expression="execution(* com.netmemex.netmx.service.transactions.impl.TransactionServiceImpl.save(..)) and args(t)"/> <aop:before pointcut-ref="encryptTransaction" method="encryptTrxAccountNumber" /> </aop:aspect> </aop:config> ...
Factory interface
Service that is looked up by the by factoryCode:public interface ComplexDuesProcessingServiceFactory { public ComplexDuesProcessingThreadImpl getService(); public ComplexDuesProcessingThread getService(String name); }
implementation of serviceCode:public interface ComplexDuesProcessingThread { public Map<Long, Long> getChargeIdMap(); public ComplexDuesForm getDuesForm(); public Master getLoggedUser(); public void run(); ... }
test case which keep giving me the class cast exceptionCode:@Service("complexDuesProcessing") @Scope("prototype") public class ComplexDuesProcessingThreadImpl implements ComplexDuesProcessingThread, Runnable { // instance of AccountItemService @Autowired @Qualifier("accountItemService") private AccountItemService accountItemService; @Async public void run() { log.debug("gets here"); AccountItem a = this.getAccountItemService().getCheckPaymentItem(); log.debug(a.getId()); }
of course the actual run implementation is a lot more complex than I am using in the example.Code:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:com/netmemex/netmx/deploy/service-layer.xml" }) @Transactional public class DuesProcessServiceTest { @Autowired @Qualifier("executorWithPoolSizeRange") private TaskExecutor taskExecutor; @Autowired @Qualifier("serviceFactory") private ComplexDuesProcessingServiceFactory complexDuesProcessingServiceFactory; @Test public void getProcess() throws NetmemexServiceException { ComplexDuesProcessingThread thread = this .getComplexDuesProcessingServiceFactory().getService( "complexDuesProcessing"); log.debug(this.getComplexDuesProcessingServiceFactory().getService( "complexDuesProcessing").getClass().getName()); // thread.run(); this.getTaskExecutor() .execute((ComplexDuesProcessingThreadImpl) thread); log.debug("done"); } }
as in the reference doc
i assumed, in the service layer, by having defined "aop config" elements with "proxy class" attribute and having an explicit <aop:aspectj-autoproxy proxy-target-class="true"/> should take care of the cglib issue.To be clear: using 'proxy-target-class="true"' on <tx:annotation-driven/>, <aop:aspectj-autoproxy/> or <aop:config/> elements will force the use of CGLIB proxies for all three of them.
Can any one help.
thanks for reading.
~s.


Reply With Quote