导航:首页 > 文件管理 > 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外部配置文件相关的资料

热点内容
有个桌面文件一直删不掉 浏览:328
文件加密内容怎么弄不了 浏览:825
修路红头文件哪里有 浏览:360
spark读文件夹 浏览:850
数据挖掘面试有哪些书 浏览:385
网络技术内容有哪些 浏览:369
小米手机游戏加速保存的视频的文件路径 浏览:505
python怎么关文件 浏览:91
什么网站服务器好 浏览:855
魔兽压缩文件密码 浏览:145
hlp格式文件转pdf格式 浏览:139
安全模式改开机密码 浏览:241
上传课堂派的时候怎么找不到文件 浏览:415
科研立项怎么做数据分析 浏览:263
2010excel教程 浏览:233
苹果5s用镊子开机图片 浏览:272
threejsvertices 浏览:616
iphone运营商修改 浏览:444
浦东新区数据技术服务电话多少 浏览:924
迅雷下载任务配置文件错误怎么办 浏览:220

友情链接