Introducing additional configuration files in spring

Source: Internet
Author: User

I. Introduction of other module XML

In the spring configuration file, sometimes it is necessary to make the configuration of the related entity class more clear for the sub-module.

For example, there is now a job-timer.xml configuration

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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 ">    <!--the task class to perform the task.  -    <BeanID= "Testquartz"class= "Com.mc.bsframe.job.TestJob"></Bean>    <!--inject the scheduled tasks that need to be performed into the job.  -    <BeanID= "Testjob"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">        < Propertyname= "TargetObject"ref= "Testquartz"></ Property>        <!--methods to be executed in the task class -        < Propertyname= "Targetmethod"value= "DoSomething"></ Property>        <!--The last time the completion is not performed, wait for it to be executed again.  -        < Propertyname= "Concurrent"value= "false"></ Property>    </Bean>    <!--The basic timer will bind to the specific task.  -    <BeanID= "Testtrigger"class= "Org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">        < Propertyname= "Jobdetail"ref= "Testjob"></ Property>        < Propertyname= "Startdelay"value= " the"></ Property>        < Propertyname= "Repeatinterval"value= "200000"></ Property>    </Bean>    <BeanID= "Scheduler"class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean">        < Propertyname= "Triggers">            <List>                <refBean= "Testtrigger"></ref>            </List>        </ Property>    </Bean></Beans>

Use <import resource= "Classpath*:/spring/job-timer.xml"/> introduced in the overall configuration file for spring.

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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 " >    <!--All packages under Com.mc.bsframe are automatically scanned, including the classes under the sub-package except @controller.  -    <Scpan:component-scanBase-package= "Com.mc.bsframe">        <Scpan:exclude-filtertype= "Annotation"expression= "Org.springframework.stereotype.Controller" />        <Scpan:exclude-filtertype= "Annotation"expression= "Org.springframework.web.bind.annotation.ControllerAdvice" />    </Scpan:component-scan>    <!--introducing additional configuration files in spring -    <ImportResource= "Classpath*:/spring/job-timer.xml" />    </Beans>

Second, the introduction of the properties file.

Method 1:

    <!---    <location = "classpath*:p roperties/ Db.properties "/>

Method 2:

Condition 1 Configures one:

    <id= "Propertyconfigurer"  class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">        <  name= "Location"  value= "classpath*:d b/jdbc.properties" />    </ Bean >

Scenario 2 Configures multiple:

    <BeanID= "Propertyconfigure"class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">        < Propertyname= "Locations">            <List>                <value>Classpath:/opt/demo/config/demo-db.properties</value>                 <value>Classpath:/opt/demo/config/demo-db2.properties</value>             </List>        </ Property>    </Bean>

These properties are key-value key-value pairs, which can be obtained using ${xxx}.

Introducing additional configuration files in spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.