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