spring bean 读取外部properties文件

方法一:利用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

    <bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:test.properties</value>
            </list>
        </property>
        <property name="fileEncoding" value="UTF-8"/>
    </bean>

方法二:利用context:property-placeholder

    <context:property-placeholder location="classpath:test.properties" file-encoding="utf-8"/>

原文地址:https://www.cnblogs.com/caohui/p/9767026.html

时间: 2024-08-03 08:22:20

spring bean 读取外部properties文件的相关文章

spring boot 读取自定义properties文件

@Configuration@Componentpublic class PropertiesConfig { private static final String[] properties = {"/application.properties"}; private static Properties props; private static Map<Object, Object> propertiesMap = new HashMap(); public Prope

SpringBoot读取application.properties文件

SpringBoot读取application.properties文件,通常有3种方式 1. @Value  例如: @Value("${spring.profiles.active}") private String profileActive;------相当于把properties文件中的spring.profiles.active注入到变量profileActive中 2. @ConfigurationProperties  例如: @Component@Configurat

Spring bean中的properties元素内的name 和 ref都代表什么意思啊?

<bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" scope="prototype"> <property name="userBO" ref="userBO" /> </bean> Spring bean中的properties元素内的name 和 ref都代表什么意思啊

fmt 国际化格式标签库(读取application.properties文件)

国际化格式标签库包括国际化,消息和数字日期格式化: (1) 国际化:<fmt:setLocale> <fmt::requestEncoding> 如: <%@ page language="java" contentType="text/html; charset=gb2312" import="java.util.*"%> <%@ taglib prefix="c" uri=&quo

springboot中读取自定义properties文件

一.在高版本的springboot中,@ConfigurationProperties(prefix = "wisely2",locations = "classpath:wisely.properties")这个注解不支持了,所以我们要另辟蹊径 二.使用组合式注解: 1.自定义config.properties文件: 1 config.fileServer=/root/jzyp/staticserver/webapps/ROOT/server 2 config.s

spring bean中的properties元素内的ref和value的区别;* 和 ** 的区别

spring bean中的properties元素内的ref和value的区别 至于使用哪个是依据你所用的属性类型决定的. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property na

spring(读取外部数据库配置信息、基于注解管理bean、DI)

###解析外部配置文件在resources文件夹下,新建db.properties(和数据库连接相关的信息) driverClassName=com.mysql.jdbc.Driverurl=jdbc:mysql://localhost:3306/dbusername=rootpassword=root 开发步骤1)创建maven工程添加web.xml添加tomcat运行环境添加jar spring-webmvc,junit,commons-dbcp,mysql添加application.xml

使用Spring注解方式注入properties文件内容,并配合Junit4+Spring做单元测试

先看看工作目录,然后再来讲解 1.建立config.properties,我的config.properties内容如下: author_name=luolin project_info=该项目主要是用于写一些demo 2.配置Spring配置文件,读取properties文件,并设置编码格式.大家从我的项目结构图中可以看到我用了两个Spring的配置文件,其实在spring-context.xml中没有配置其他内容,只是配置扫描com.eya.property这个包,大家可能会有疑问为何包的扫

spring配置中,properties文件以及xml文件配置问题

spring方便我们的项目快速搭建,功能强大,自然也会是体系复杂! 这里说下配置文件properties管理的问题. 一些不涉及到代码逻辑,仅仅只是配置数据,可以放在xxxx.properties文件里面,项目功能复杂的时候,往往properties文件很多,这时,就比较容易让人困惑,有些properties的文件内容总是加载不起来,应用启动时,就不断爆出错误,说某某参数加载失败,这个是什么原因呢? 其实,这个是spring配置的时候,org.springframework.beans.fact