Announcement Announcement Module
Collapse
No announcement yet.
Problem configuring Spring AOP and scheduling with quartz spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem configuring Spring AOP and scheduling with quartz spring

    Hello,
    I have an application that logs need to do and I'm using AOP. But it was necessary to create a class to use the quartz and the application no longer works.

    I'm using: Spring 2.5, quartz and aspectj.

    Below is my configuration file (applicationContext.xml)
    Code:
    <?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.5.xsd 
    	http://www.springframework.org/schema/aop 
    	http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
    
    	<aop:aspectj-autoproxy />
    
    	<!-- Aspect -->
    	<bean id="logAspect" class="br.gov.am.prodam.log.Log4Aop" />
    
    	<!-- Hibernate SessionFactoryAFI -->
    	<bean id="jbossTransactionManager"
    		class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple">
    	</bean>
    
    	<bean id="jbossUserTransaction"
    		class="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple" />
    
    	<!-- Transaction manager for a single Hibernate SessionFactory (alternative 
    		to JTA) -->
    	<bean id="transactionManager"
    		class="org.springframework.transaction.jta.JtaTransactionManager">
    		<property name="transactionManager">
    			<ref bean="jbossTransactionManager" />
    		</property>
    		<property name="userTransaction">
    			<ref bean="jbossUserTransaction" />
    		</property>
    	</bean>
    
    	<bean id="testeServiceTarget" class="br.gov.am.prodam.log.teste.TesteService1" />
    
    	<bean id="testeService"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager" ref="transactionManager" />
    		<property name="target" ref="testeServiceTarget" />
    		<property name="transactionAttributes">
    			<props>
    				<prop key="*">PROPAGATION_REQUIRED</prop>
    			</props>
    		</property>
    	</bean>
    
    
    	<bean id="jobObj" class="br.gov.am.prodam.log.teste.Job" />
    
    	<bean id="job"
    		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    		<property name="targetObject" ref="jobObj" />
    		<property name="targetMethod" value="methodJob" />
    	</bean>
    
    	<bean id="triggerJob" class="org.springframework.scheduling.quartz.CronTriggerBean">
    		<property name="jobDetail" ref="job" />
    		<property name="cronExpression" value="0 0 8 * * ?" />
    		<property name="jobDataAsMap">
    			<map>
    				<entry key="triggerMessage" value="Iniciando Exclusão de Registros de BO Rascunhos" />
    			</map>
    		</property>
    	</bean>
    
    	<bean id="schedulerFactory"
    		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    		<property name="triggers">
    			<list>
    				<ref local="triggerJob" />
    			</list>
    		</property>
    	</bean>
    
    
    </beans>
    statck Trace
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'triggerJob' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy13 implementing java.lang.Cloneable,java.io.Serializable,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.quartz.JobDetail] for property 'jobDetail'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy13 implementing java.lang.Cloneable,java.io.Serializable,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.quartz.JobDetail] for property 'jobDetail': no matching editors or conversion strategy found
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at br.gov.am.prodam.log.teste.Teste.main(Teste.java:9)
    Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy13 implementing java.lang.Cloneable,java.io.Serializable,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.quartz.JobDetail] for property 'jobDetail'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy13 implementing java.lang.Cloneable,java.io.Serializable,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.quartz.JobDetail] for property 'jobDetail': no matching editors or conversion strategy found
    	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    	... 14 more
    Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy13 implementing java.lang.Cloneable,java.io.Serializable,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.quartz.JobDetail] for property 'jobDetail': no matching editors or conversion strategy found
    	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
    	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
    	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
    	... 18 more
    I thank!

  • #2
    Hi. It looks like you have a jdk proxy around your job bean. Make sure that no aspect you define is applied to the job bean.
    A quick dirty fix can be to use <aop:aspectj-autoproxy proxy-target-class="true" />. This will not create a jdk proxy (on interfaces) but a proxy implemented as JobDetail subclass, which can be injected into a CronTriggerBean. But you should prefere to get rid of the proxy since proxying JobDetail does not have any sense to me.

    Comment

    Working...
    X