日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring中引入其他配置文件

發布時間:2025/3/11 javascript 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring中引入其他配置文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文:http://www.cnblogs.com/LiuChunfu/p/5605473.html

------------------------------------------------------------------------------


一、引入其他 模塊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>

二、引入properties文件。

方法1:

<!--引入數據庫配置信息 --><context:property-placeholder location="classpath*:properties/db.properties" />

方法2:

情況1配置一個:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="location" value="classpath*:db/jdbc.properties" /></bean>

情況2配置多個:

<bean id="propertyConfigure" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/opt/demo/config/demo-db.properties</value> <value>classpath:/opt/demo/config/demo-db2.properties</value> </list></property></bean>

這些properties中就是key-value的鍵值對,使用的時候可以使用${xxx} 獲取。



總結

以上是生活随笔為你收集整理的Spring中引入其他配置文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。