Spring中引入其他配置文件
来源:互联网 发布:tcp网络调试助手 编辑:程序博客网 时间:2024/05/16 11:09
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} 获取。
阅读全文
0 0
- Spring中引入其他配置文件
- Spring中引入其他配置文件
- spring的配置文件中引入其他配置
- spring中引入其他文件
- Spring中引入其它配置文件
- spring 配置文件中 引入properties文件
- Spring 3 中引入properties配置文件
- spring 引入数据库配置文件
- spring引入配置文件
- spring学习-引入配置文件
- spring 配置文件引入properties
- spring 引入外部配置文件
- Spring引入配置文件
- Spring配置文件中注入环境变量或其他配置文件变量
- Spring配置文件与Struts配置文件中导入其他文件
- spring 引入数据库配置(其他配置文件.properties)文件的两种方式
- web.xml中引入SPRING配置文件classpath的含义
- spring引入多个配置文件
- (十五)消息队列MQ
- Android studio http请求获取数据失败或者获取不到数据原因
- Qt定时器事件与计数器
- 火爆不亚于中国?看看印度聊天机器人市场现状 | 分析
- 政府牵头!中国要造强大AI芯片挑战英伟达地位 | 聚焦
- Spring中引入其他配置文件
- spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务
- 按钮动画
- 评论抓取:Python爬取微信在APPStore上的评论内容及星级
- fopen
- PHP魔术方法:Typecho反序列化漏洞
- recyclerview多条目加载
- 初学logistic回归
- Kafka java api-生产者代码、高性能吞吐