Spring多资源文件properties的配置

Spring简化了加载资源文件的配置,可以通过<context:property-placeholder去加载,这个元素的写法如下:

<context:property-placeholder location="classpath:jdbc.properties"/>

如果想要配置多个properties文件

<context:property-placeholder location="classpath:jdbc.properties"/>

<context:property-placeholder location="classpath:app.properties"/>

这种方式是不被允许的,一定会出"Could not resolve placeholder"。

解决方案:

(1) 在Spring 3.0中,可以写:

<context:property-placeholder location="jdbc.properties" ignore-unresolvable="true"/>

<context:property-placeholder location="app.properties" ignore-unresolvable="true"/>

(2) 但是在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,所以就不能使用上面的那种方法去配置,

可以改如下的格式:

<bean id="propertyConfigurer"

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<list>

<value>classpath:/jdbc.properties</value>

</list>

</property>

</bean>
时间: 2024-08-03 17:38:55

Spring多资源文件properties的配置的相关文章

maven资源文件的相关配置

https://www.cnblogs.com/pixy/p/4798089.html https://blog.csdn.net/u011900448/article/details/78281269 https://www.cnblogs.com/hi-feng/p/7892724.html maven资源文件的相关配置构建Maven项目的时候,如果没有进行特殊的配置,Maven会按照标准的目录结构查找和处理各种类型文件.src/main/java和src/test/java 这两个目录中的

spring配置国际化的消息资源文件(.properties)

<!-- 引入属性文件 --> <!--加载config.properties文件--> <context:property-placeholder location="classpath:config.properties" /> <!-- 国际化的消息资源文件 --> <bean id="messageSource"         class="org.springframework.contex

maven 打包时动态替换properties资源文件中的配置值

pom build节点下面添加resource配置: [html] view plain copy <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> </includ

SpringBoot系列四:SpringBoot开发(改变环境属性、读取资源文件、Bean 配置、模版渲染、profile 配置)

1.概念 SpringBoot 开发深入 2.具体内容 在之前已经基本上了解了整个 SpringBoot 运行机制,但是也需要清楚的认识到以下的问题,在实际的项目开发之中,尤其是 Java 的 MVC 版项目里面,所有的项目都一定需要满足于如下几点要求: · 访问的端口不能够是 8080,应该使用默认的 80 端口: · 在项目之中为了方便进行数据的维护,建议建立一系列的*.properties 配置文件,例如:提示消息.跳转路径: · 所有的控制器现在都采用了 Rest 风格输出,但是正常来讲

SpringMVC对静态资源文件的访问(配置)

<!-- 自动扫描的包名 -->     <context:component-scan base-package="com.app,com.core,JUnit4" ></context:component-scan>          <!-- 默认的注解映射的支持 -->     <mvc:annotation-driven />          <!-- 视图解释类 -->     <bean cl

读取spring配置文件的方法(spring读取资源文件)

1.spring配置文件 <bean id="configproperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:jdbc.properties"/> </bean> 2.读取属性方法 Appli

Spring中属性文件properties的读取与使用

实际项目中,通常将一些可配置的定制信息放到属性文件中(如数据库连接信息,邮件发送配置信息等),便于统一配置管理.例中将需配置的属性信息放在属性文件/WEB-INF/configInfo.properties中. 其中部分配置信息(邮件发送相关): Java代码 #邮件发送的相关配置 email.host = smtp.163.com email.port = xxx email.username = xxx email.password = xxx email.sendFrom = xxx@16

使用Spring读取xml文件中的配置信息

一般写程序时我们都会将一些配置信息写到配置文件中,以便在不修改源码的情况下对程序的某些点进行更改.这里介绍一种Spring读取xml配置文件的方式,其基本思路如下:定义一个java类,其中定义一些静态变量对应我们的配置信息,然后采用注入的方式将变量值初始化为配置值.示例代码如下: 新建一个java类: package java; public class Config { //要配置的值 public static int value = 0; //这里不能写成静态的 public void s

java读取资源文件(Properties)

四步: java代码 //new一个读取配置文件 Properties properties=new Properties(); //获取文件路径 String path=request.getServletContext().getRealPath("/dom.properties"); //读取文件内容 properties.load(new FileInputStream(path)); //获取origin的value String origin=properties.getP