Spring中引入其他配置文件
一、引入其他 模块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中引入其他配置文件的更多相关文章
- SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在Java配置文件中引入xml配置文件@Import、@ImportResource
1. package soundsystem; import org.springframework.beans.factory.annotation.Autowired; public class ...
- ssh整合思想初步 struts2与Spring的整合 struts2-spring-plugin-2.3.4.1.jar下载地址 自动加载Spring中的XML配置文件 Struts2下载地址
首先需要JAR包 Spring整合Structs2的JAR包 struts2-spring-plugin-2.3.4.1.jar 下载地址 链接: https://pan.baidu.com/s/1o ...
- SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在XML配置文件中引入JAVA配置文件 <import> 、<bean>
一.在xml中引入xml,用<import> <?xml version="1.0" encoding="UTF-8"?> <be ...
- Spring之配置文件中引入其它配置文件
<beans> ... <!--引入其它配置文件--> <import resource="classpath:com/helloworld/beans.xml ...
- Spring中加载配置文件的方式
原文:http://blog.csdn.net/snowjlz/article/details/8158560 Spring 中加载XML配置文件的方式,好像有3种, XML是最常见的Spring 应 ...
- Spring中手动增加配置文件中占位符引用的变量
在项目中遇到一个这样的需求,项目的配置文件由外部传入,这时spring配置文件那些占位符变量该如何取值呢? 解决这个问题的做法有几种,我想到的大概有以下三种: 1.通过系统属性来实现,把外部传入的配置 ...
- Spring中获取外部配置文件中的属性值
很多时候需要将配置信息从程序中剥离粗来,Spring现在提供的方法是通过@Value注解和<context:placeholder>来获取配置文件中的配置信息.这里给出一个简单的例子. 首 ...
- 模拟Spring中applicationContext.xml配置文件初始化bean的过程
package com.xiaohao.action; import java.io.File; import java.lang.reflect.Method; import java.util.C ...
- spring中引入多个quertz 注意事项
每一个独立的调取任务 需起不同的名字,否则只有最后一个调度起作用其他不起作用
随机推荐
- python unitest基本
基本 import unittest class OneTest(unittest.TestCase): def setUp(self): self.verificationErrors = [] s ...
- hdu_2243_考研路茫茫——单词情结(AC自动机+矩阵)
题目链接:hdu_2243_考研路茫茫——单词情结 题意: 让你求包含这些模式串并且长度不小于L的单词种类 题解: 这题是poj2788的升级版,没做过的强烈建议先做那题. 我们用poj2778的方法 ...
- qsdk编译
QSDK是一种在openwrt的基础上,加入了高通atheros芯片相关资料的一种环境. QSDK与openwrt的区别主要在如下几个方面: arch/mips/ath79/* – updated Q ...
- C语言strtok()函数:字符串分割
头文件:#include <string.h> 定义函数:char * strtok(char *s, const char *delim); 函数说明:strtok()用来将字符串分割成 ...
- divide an integer into X parts (as even as possible)
the algorithm is like this: it evenly spreads an integer N over K cells. for i = 0 to K array[i] = N ...
- oc拨打电话
判断当前设备是否支持电话功能 +(int)isCanCall{ if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad || [[[UIDevi ...
- Linux系统的时区和时间调整
linux调整系统时区: 1)tzselect命令 找到相应的时区文件/usr/share/zoneinfo/Asia/Shanghai,用这个文件替换当前的/etc/localtime文件. 或者 ...
- linux expr命令参数及用法详解
expr用法 expr命令一般用于整数值,但也可用于字符串.一般格式为: #expr argument operator argument expr也是一个手工命令行计数器. #$expr 10 + ...
- Qt 学习之路 2(84):Repeater
前面的章节我 们介绍过模型视图.这是一种数据和显示相分离的技术,在 Qt 中有着非常重要的地位.在 QtQuick 中,数据和显示的分离同样也是利用这种"模型-视图"技术实现的.对 ...
- Inno Setup入门(十九)——Inno Setup类参考(5)
: Install Setup 2013-02-02 11:29 377人阅读 评论(0) 收藏 举报 单选按钮 单选按钮在安装中也很常见,例如同一个程序可以选择安装不同的性质的功能,例如选择32位或 ...