代码之家  ›  专栏  ›  技术社区  ›  Syed

无法在应用程序上下文配置文件中添加任务计划程序标记

  •  0
  • Syed  · 技术社区  · 6 年前

    我创建了一个简单的spring应用程序,并试图在其中添加一个新的任务调度器作业。当我配置它时,它会给出编译时错误。我在谷歌上搜索了很多,但不知道为什么会这样。。这是我的配置文件。有什么想法吗

    <?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:c="http://www.springframework.org/schema/c"
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.1.xsd">
    
    
    <context:component-scan base-package="com.ibm.spring" />
    

    <bean id="location" class="com.ibm.spring.Location" autowire="byName"  scope="singleton">
        <property name="addresses">
            <list>
                <ref bean="address2"></ref>
            </list>
        </property>
    </bean>
    
    <bean id="address1" class="com.ibm.spring.Address">
        <property name="id" value="1"></property>
        <property name="street" value="shahjahan"></property>
    </bean>
    
    <bean id="address2" class="com.ibm.spring.Address">
        <property name="id" value="2"></property>
        <property name="street" value="Akbar"></property>
    </bean> 
    <bean id="restaurant" class="com.ibm.spring.Restaurant" scope="prototype">
    </bean>
    
    <task:scheduled-tasks scheduler="printingScheduler">
       <task:scheduled ref="printer" method="print" fixed-delay="3000" />
     </task:scheduled-tasks>
    
     <task:scheduler id="printingScheduler" />
    
    </beans>
    

    它显示的编译时错误如下

    The prefix "task" for element "task:scheduled-tasks" is not 
    

    已绑定。

    2 回复  |  直到 6 年前
        1
  •  2
  •   Robert Moskal    6 年前

    这是因为您没有在spring上下文文件的头部声明任务名称空间。我不确定当前版本是什么,但您需要执行以下操作:

    bean标记需要任务命名空间声明和架构位置:

    <bean... xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="...
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
    
    "
    
    推荐文章