2014-02-25 84 views
-1

我工作的一個Spring Roo的Web應用程序,並需要使用,在後臺運行,每隔一定時間排定方法Spring的ApplicationContext的配置,然後我添加了一些 行我applicationContext.xml中,並且該方法跑了好了,但隨後發生 該應用程序無法設置/讀取 transactionManager的,控制檯說:The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.爲計劃方法

我已經搜查,並在此網站上發現,2個或3回答此錯誤消息,這樣的aS:

  1. add xmlns:tx="http://www.springframework.org/schema/tx to th Ë 頭[已經完成]
  2. tx:annotation前加component:scan [已經完成]但是當我嘗試在服務器上運行我的應用程序,它拋出一個 HTTP Status 404 The Requested Resource is not available,你能 幫我解決xml文件?

這是我的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> 

回答

0

你做

xmlns:tx="http://www.springframework.org/schema/tx" 

宣佈tx命名空間的使用,但你忘了申報XSD的位置,此命名空間中xsi:schemaLocation屬性:

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