spring集成quartz报数据库链接问题

<?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:context="http://www.springframework.org/schema/context"     
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans         
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd         
  http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/context  
      http://www.springframework.org/schema/context/spring-context.xsd"
      default-autowire="byName">

<bean id="quartzJob" class="com.study.spring.quartz.QuartzJob" />

<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="quartzJob" />
<property name="targetMethod" value="myJob" />
<property name="concurrent" value="false"/>
<!-- 是否允许任务并发执行。当值为false时,表示必须等到前一个线程处理完毕后才再启一个新的线程 -->
</bean>

<bean id="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail"/>
<property name="cronExpression" value="*/1 * * * * ?" /><!-- 每隔一秒触发一次 -->
</bean>

<bean id="batchQuartz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
      <!-- 此处可以配置其他属性,包括加载配置文件等 -->
<property name="triggers"> 
           <list> 
              <ref bean="myTrigger"/> 
           </list> 
       </property> 
</bean>
</beans>

=========================================================================
以上中定义batchQuartz的bean,启动服务时,一直报org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchQuartz' defined in class path resource [conf/spring/spring-quartz.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${jdbc.driverClassName}'

解决方式:
在定义batchQuartz时,配置 autowire="no",不让自动装配,否则PropertyPlaceholderConfigurer失效,也就是用${jdbc.username}这样之类的表达式,将无法获取到properties文件里的内容

猜你喜欢

转载自zbzjutsoft.iteye.com/blog/2331331
今日推荐