Spring配置文件引入xml文件: <import resource=" " />标签使用总结
引入其他模块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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决