Spring基础之加载外部文件
一、用注解加载(@PropertySource)
@PropertySource(value = { "classpath:jdbc.properties" },ignoreResourceNotFound = true)
public class ApplicationCongfig {
}
- ignoreResourceNotFound boolean值,默认是false,含义是如果找不到文件是否将其忽略,在默认情况在找不到文件或抛出异常。
- name 配置这次属性的名称。
- value 字符创数组,可以配置多个属性文件。
二、通过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:context="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-4.3.xsd"> <!--扫描加注解的包 --> <context:component-scan base-package="cn.bzu.springpractice"></context:component-scan> <!-- 加载外部文件 --> <context:property-placeholder ignore-resource-not-found="false" location="classpath:jdbc.properties"/> </beans>
作者:银龙
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!
浙公网安备 33010602011771号