1. 程式人生 > >Spring SpringMvc 3.0 + MyBatis 整合--補充關於.properties檔案的讀取

Spring SpringMvc 3.0 + MyBatis 整合--補充關於.properties檔案的讀取

上篇文章中關於.propertis檔案的每條記錄在xml檔案裡面配置,如下圖

新方法: 專案啟動時候自動掃描.propertis裡面的每條內容到map中.

配置檔案:

<bean id="myPropertyConfigurer" class="com.ass.base.prop.MyPropertyConfigurer">
		<property name="ignoreUnresolvablePlaceholders" value="true" />
		<property name="locations">
			<list>
				<value>/WEB-INF/config/config.properties</value>
				<value>/WEB-INF/config/system.properties</value>
				<value>/WEB-INF/config/approval.properties</value>
			</list>
		</property>
	</bean>

類:

package com.ass.base.prop;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class MyPropertyConfigurer extends PropertyPlaceholderConfigurer {

	private Map<String, String> myPropertiesMap;

	@Override
	protected void processProperties(ConfigurableListableBeanFactory factory, Properties props) throws BeansException {
		super.processProperties(factory, props);
		
		myPropertiesMap = new HashMap<String, String>();
		for (Object key : props.keySet()) {
			String keyStr = key.toString();
			String value = props.getProperty(keyStr);
			myPropertiesMap.put(keyStr, value);
		}
	}

	public String getVal(String name) {
		return myPropertiesMap.get(name);
	}

}

使用方式:

	@Resource
	private MyPropertyConfigurer myPropertyConfigurer;
	
	/**
	 * 獲取properties檔案值的方法,通過key獲取value
	 * @param key
	 * @return
	 * @author wangt 2014年12月5日 上午9:11:39 
	 */
	public String getProp(String key) {
		return myPropertyConfigurer.getVal(key);
	}
	

相關推薦

Spring SpringMvc 3.0 + MyBatis 整合--補充關於.properties檔案讀取

上篇文章中關於.propertis檔案的每條記錄在xml檔案裡面配置,如下圖 新方法: 專案啟動時候自動掃描.propertis裡面的每條內容到map中. 配置檔案: <bean id

Spring SpringMvc 3.0 + MyBatis 整合

一、使用的jar包就不詳細講解了,下載了Mybatis 和 Spring 的jar包基本上都新增上去了、 一圖概括:(這是我使用的ar包,有些不是Mybatis 和 Spring 的 ) 二、 web.xml配置檔案 <?xml version="1.0" en

Spring Boot 學習系列(07)—properties檔案讀取

此文已由作者易國強授權網易雲社群釋出。 歡迎訪問網易雲社群,瞭解更多網易技術產品運營經驗。 傳統的properties讀取方式 一般的,我們都可以自定義一個xxx.properties檔案,然後在工程的xml配置檔案中注入相關的配置bean,示例如下:<context:property-placeh

Spring 4.2.2 and apache tiles 3.0.5 整合

記錄 Spring 4.2.2 整合 apache tiles 3.0.5 的步驟   pom.xml <dependency> <groupId>org.apache.tiles</groupId> <a

Spring-mybatis整合 獲取properties 建立SQLSessionFactory失敗

程式碼: <bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" v

spring 3.2+mybatis 整合報錯問題

2015-7-17 17:44:09 org.springframework.context.support.AbstractApplicationContext prepareRefresh 資訊: Refreshing org[email protected]

意料之外,情理之中,Spring.NET 3.0 版本發布-

system 幫助 緩存 lib 如何 frame 問題 問題跟蹤 信息 意料之外,情理之中,Spring.NET 3.0 版本發布- 備受社區和企業開發者廣泛關註的Spring.NET在上周發布了3.0版本,並且目前已經保持著持續的更新,讓我們一起來看一看他究竟發

Spring Boot 3Mybatis

ORM 框架是什麼 ORM(Object-Relation Mapping),是一種程式設計技術,能夠實現面向物件程式語言與關係型資料庫之間的資料轉換(對映),解決了面向物件與關係資料庫存在的互不匹配的現象。 ORM 是通過使用描述物件和資料庫之間對映的元資料,將程式中的物件自動持久化到關係資料庫中。

spring boot 2.0 +mybatis + tk+MBG

直接上程式碼 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x

Swift程式設計入門外傳 — 3.0版修訂補充

Swift程式設計入門外傳 — 3.0版修訂補充包“Swift程式設計入門”當初撰寫時,Swift 還是1.2版,才一眨眼的功夫它就進化到 3.0 版。彼得潘特別將書中一些需調整的內容整理出來,希望可以幫助大家在閱讀時無痛轉換到 3.0 版。點選Edit -> Emoji & Symbols 開

spring + redis + spring-data-redis2.0.10 整合-redis Cluster版

單機版 原始碼下載   下載 redis-cluster分支 和單機版不同的地方 1 .新增配置檔案redisClust.properties spring.redis.cluster.max-redirects=3 spring.redis.cluster.node

spring boot 2.0 mybatis redid

----------------------------------pom.xml--------------------------------------- <!--快取--> <dependency> <groupId>

springMVC系列之(四) spring+springMVC+hibernate 三大框架整合

         首先我們要知道Hibernate五大物件:,本例項通過深入的使用這五大物件和spring+springMVC相互結合,體會到框架的好處,提高我們的開發效率          Hibernate有五大核心介面,分別是:Session Transaction

Spring Boot(3)--使用Mybatis

本章內容 新增mybatis支援 多資料來源配置 總結         前一章也說過,連線使用資料庫主要有兩種方式,一種是ORM框架,使用對像來生成需要的SQL,代表的有JPA和Hibernate。另一種方式就是直接使用SQL操作

jdk 1.8 與 spring+springmvc 3.2 .jar 啟動tomcat報錯

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener or

Spring Boot 2.0 + MyBatis + pageHelper 多元資料庫分頁

繼之前在MyBatis設定多元資料的情況下,在工作中又遇到了多元資料庫分頁失效的問題,如下是解決過程。 這裡先貼上我之前解決多元資料的部落格:https://blog.csdn.net/jiangxiaoyi_07/article/details/84982875 先介紹只有一個數據源的情況

Spring boot 2.0+ MyBatis 多資料來源(多Mysql)

業務的需求需要兩個在不同伺服器的資料庫。 首先確定Springboot版本,我這裡引用的是2.0.0 <parent> <groupId>org.springframework.boot</groupId> <artifactId&g

Springmvc+Apache Camel+Mybatis整合例項及分析

Spring MVC+Apache Camel+Mybatis整合例項及分析 最近在學習camel,公司之前做過的專案使用到了camel進行了很多工作。就連資料庫的操作也是通過camel來完成的。至於用camel來操作資料庫有什麼優點,目前就我自己的體會來說,利用came

關於springspring-framework-3.0.2.RELEASE-dependencies.zip包的下載

今天在java 吧裡面發現了一個大神說,其實,ssh 已經綁架了我們java的新學者,首先,嘴面上我是不承認,但是我的內心不得不承認這是事實。ssh已經綁架了我們這些新學者,而我,作為一個新學者,竟然花費了一整個暑假在這三個框架上,說後悔,我倒不至於,但是呢,總是覺得,時間

GreenDAO 3.0 資料庫整合,使用,升級

import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.suppo