標簽使用總結" type="hidden"/>

Spring配置文件引入xml文件: 標簽使用總結


引入其他模塊XML

  在Spring的配置文件,有時候為了分模塊的更加清晰的進行相關實體類的配置。

  比如現在有一個job-timer.xml的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 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.xsd">

    <!-- 要執行任務的任務類。 -->
    <bean id="testQuartz" class="com.mc.bsframe.job.TestJob"></bean>

    <!-- 將需要執行的定時任務注入JOB中。 -->
    <bean id="testJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="testQuartz"></property>
        <!-- 任務類中需要執行的方法 -->
        <property name="targetMethod" value="doSomething"></property>
        <!-- 上一次未執行完成的,要等待有再執行。 -->
        <property name="concurrent" value="false"></property>
    </bean>

    <!-- 基本的定時器,會綁定具體的任務。 -->
    <bean id="testTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
        <property name="jobDetail" ref="testJob"></property>
        <property name="startDelay" value="3000"></property>
        <property name="repeatInterval" value="200000"></property>
    </bean>

    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="testTrigger"></ref>
            </list>
        </property>
    </bean>
</beans>

  在Spring的整體的配置文件中使用 <import resource="classpath*:/spring/job-timer.xml" />引入。

<?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:scpan="http://www.springframework.org/schema/context"   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 會自動掃描com.mc.bsframe下的所有包,包括子包下除了@Controller的類。 --> <scpan:component-scan base-package="com.mc.bsframe"> <scpan:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <scpan:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" /> </scpan:component-scan> <!-- Spring中引入其他配置文件 --> <import resource="classpath*:/spring/job-timer.xml" /> </beans>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM