用于调度方法的Spring applicationContext配置

时间:2014-02-25 16:22:46

标签: spring

我正在开发一个Spring Roo网络应用程序,并且需要使用每隔一段时间在后台运行的Scheduled方法,然后我添加了一些 到我的applicationContext.xml的行,该方法运行正常,但随后 发现应用程序无法设置/读取 事务管理器,控制台说The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.

我已经搜索过了,并在本网站上找到了这个错误消息的2或3个答案,例如:

  1. xmlns:tx="http://www.springframework.org/schema/tx添加到 标题[已完成]
  2. component:scan [已完成]之前添加tx:annotation但是当我尝试在服务器上运行我的应用时,它会抛出 一个HTTP Status 404 The Requested Resource is not available,你能吗? 帮我修复xml文件?
  3. 这是我的applicationContext.xml文件:

     <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <beans xmlns="http://www.springframework.org/schema/beans" 
        xmlns:context="http://www.springframework.org/schema/context" 
        xmlns:mvc="http://www.springframework.org/schema/mvc" 
        xmlns:p="http://www.springframework.org/schema/p" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd                 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.1.xsd                 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd 
        http://www.springframework.org/schema/task  
        http://www.springframework.org/schema/task/spring-task-3.0.xsd"
        xmlns:task="http://www.springframework.org/schema/task"
        xmlns:tx="http://www.springframework.org/schema/tx">        
    
        <context:component-scan base-package="org.webapp.services.tasks">
        </context:component-scan>   
        <task:annotation-driven />    
        <bean id="scheduledMethod" class="com.myhome.myproject.web.ScheduledJobsController">         
        </bean>        
        <context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
        <context:spring-configured/>
        <context:component-scan base-package="com.myhome.myproject">
        <context:exclude-filter expression=".*_Roo_.*" type="regex"/>
        <context:exclude-filter expression="org.springframework.stereotype.Controller"         type="annotation"/>
        </context:component-scan>
        <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"     id="dataSource">
        <property name="driverClassName" value="${database.driverClassName}"/>
        ...
        </bean>
        <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
        </bean>   
        <context:component-scan base-package="com.myhome.myproject"></context:component-scan>
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>    
        <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"     id="entityManagerFactory">
        <property name="persistenceUnitName" value="persistenceUnit"/>
        <property name="dataSource" ref="dataSource"/>
        </bean>
        </beans>
    

1 个答案:

答案 0 :(得分:0)

您通过执行

声明了tx命名空间的用法
xmlns:tx="http://www.springframework.org/schema/tx"

但您忘记在xsi:schemaLocation属性中声明此命名空间的xsd位置:

http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd