導航:首頁 > 文件管理 > string外部配置文件

string外部配置文件

發布時間:2024-08-24 07:03:24

⑴ 中方法返回值為string類型,mybatis配置文件中怎麼配置

一.Mybatis簡介 MyBatis由Clinton Begin 在2002 年創建,其後,捐獻給了Apache基金會,成立了iBatis 項目。2010 年5 月,將代碼庫遷至Google Code,並更名為MyBatis。 MyBatis 是一個可以自定義SQL、存儲過程和高級映射的持久層框架。

⑵ 如何在spring中讀取properties配置文件裡面的信息

首先我使用的是註解的方式。

  1. 創建properties配置文件Key=value的形式

  2. 在spring的配置文件中進行導入專代碼如下:屬

    <util:properties id="test" location="classpath:test.properties"/>

提示:路徑問題自己把握

3.在你需要使用的類中這樣:

private @Value("#{test['isOpen']}") String isOpen;

記得寫getset方法

isOpen這個在test.properties中是這樣的:

isOpen=true


如果有任何問題,可追加。望採納

java如何指定外部的配置文件

public class ConfigManager {
protected final static org.slf4j.Logger logger = LoggerFactory.getLogger(ConfigManager.class); private boolean autoReload; private static final String BASE_PATH; private static final String GLOBAL_CONFIG_PATH = "global.config.path"; private static final String fileName="conf.properties"; private static volatile PropertiesConfiguration prop =null; static{
logger.info("開始初始化ConfigurationManager===================== ");
SystemConfiguration sysConfig = new SystemConfiguration();
String globalPath = sysConfig.getString(GLOBAL_CONFIG_PATH);
logger.info("globalPath======================= "+globalPath); if(StringUtils.isBlank(globalPath)){/**默認載入classpath下面的文件**/
globalPath = Thread.currentThread().getContextClassLoader().getResource("conf.properties").getFile();
}
BASE_PATH=globalPath;
} public ConfigManager(boolean autoReload) throws ConfigurationException { this.autoReload=autoReload;
loadConfig();
} public void loadConfig() throws ConfigurationException { if (null==prop){
prop=new PropertiesConfiguration();
}
File file=new File(BASE_PATH);
prop.setFile(file);
prop.setAutoSave(false); if(autoReload){/**重載策略,5秒鍾監視文件變化***/
prop.setReloadingStrategy(new FileChangedReloadingStrategy());
}
prop.load();

} /**
* @param key
* @return value
*/
public String getProperty(String key) { return prop.getString(key);
} /**
* 獲取整數類型的配置項
*
* @param key
* @return value
*/
public Integer getInteger(String key) {
String value = getProperty(key); return Integer.valueOf(value);
} /**
* 獲取布爾類型的配置項
*
* @param key
* @return value
*/
public Boolean getBoolean(String key) {
String value = getProperty(key); return Boolean.valueOf(value);
} /**
* 獲取Long類型的配置項
*
* @param key
* @return
*/
public Long getLong(String key) {
String value = getProperty(key); return Long.valueOf(value);
} private static class SingletonHelp {
static ConfigManager instance; static { try {
instance = new ConfigManager(true);
} catch (ConfigurationException e) {
logger.error("ConfigurationManager error" +e);
}
}
} public static ConfigManager build(){ return SingletonHelp.instance;
}

}

⑷ 如何使用外部配置文件

摘要:我們知道在Enterprise Library1.1中對於每一個應用程序塊都有一個對應的配置文件,而在Enterprise Library2.0中卻把所有的配置信息都放在了應用程序配置文件(App.config或Web.config)中,在2.0下,我們如何使用外部配置文件?如何為每個應用程序塊創建對應的配置文件?

主要內容
1.不使用外部配置文件
2.使用不同的ConfigurationSource
3.使用多個ConfigurationSource
4.使用.NET的configSource特性

一.不使用外部配置文件
我們先來看一個簡單的使用Enterprise Library的例子,在這個示例中,使用了企業庫的Data Access Application Block和 Excepiton Handling Application Block。
using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

using Microsoft.Practices.EnterpriseLibrary.Data;

using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace EntLibConfig
{
class Program
{
static void Main(string[] args)
{
try
{
Database db = DatabaseFactory.CreateDatabase("EntLibInstance");

db.ExecuteNonQuery("ProcName");
}
catch (Exception ex)
{
if (ExceptionPolicy.HandleException(ex, "Event Policy"))

throw;
}
}
}
}
使用Enterprise Library Configuration配置之後,App.config文件如下:
<?xml version="1.0" encoding="utf-8"?>

<configuration>

<configSections>

<section name="exceptionHandling" type="Microsoft.Practices.
EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />

</configSections>

<exceptionHandling>

<exceptionPolicies>

<add name="Event Policy">

<exceptionTypes>

<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

postHandlingAction="ThrowNewException" name="Exception">

<exceptionHandlers>

<add exceptionMessage="This is a test!" replaceExceptionType=
"Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"

type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.
EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"

name="Replace Handler" />

</exceptionHandlers>

</add>

</exceptionTypes>

</add>

</exceptionPolicies>

</exceptionHandling>

<dataConfiguration defaultDatabase="EntLibInstance" />

<connectionStrings>

<add name="EntLibInstance" connectionString="Server=./SQLEXPRESS;Integrated Security=SSPI;Database=Northwind;"

providerName="System.Data.SqlClient" />

</connectionStrings>

</configuration>
我們知道在EL1.1下,對於不同的應用程序塊是放在了不同的配置文件中,而到了2.0中可以看到,所有的配置信息都放在了應用程序配置文件中(App.config或者Web.config)。

⑸ 數據持久層中方法返回值為string類型,mybatis配置文件中怎麼配置

select裡面的resultClass="String"

閱讀全文

與string外部配置文件相關的資料

熱點內容
e420硬體升級 瀏覽:225
QQ域名防紅代碼 瀏覽:756
viahdwin10 瀏覽:448
360軟體小助手怎麼添加文件夾 瀏覽:401
電視內置網路有什麼好處 瀏覽:81
微信10分鍾下款口子 瀏覽:62
中國買賣書畫的網站有哪個 瀏覽:648
vb程序最小公倍數 瀏覽:747
迅雷雲盤下載的文件怎麼找不到 瀏覽:49
樹莓派做win10電視盒子 瀏覽:690
模仁編程是什麼意思 瀏覽:267
分數app 瀏覽:135
硬碟格式化文件系統 瀏覽:325
如果禁用分頁文件 瀏覽:80
公司級的路由器密碼設置 瀏覽:581
京東app的好物榜怎麼進 瀏覽:803
word打開臨時文件夾 瀏覽:686
如何復制選中的數據 瀏覽:96
ios打開本地文件 瀏覽:816

友情鏈接