c3p0配置文件应该放在哪?

南院逍大王 发布于 2012/03/05 13:11
阅读 11K+
收藏 1

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

我讲c3p0-config.xml放在src目录下,程序以app运行没有错误,但是以web server运行,就会解析不到配置~

官网上有以下一段话:

By default, c3p0 will look for an XML configuration file in its classloader's resource path under the name "/c3p0-config.xml". That means the XML file should be placed in a directly or jar file directly named in your applications CLASSPATH, in WEB-INF/classes, or some similar location. If you prefer not to bundle your configuration with your code, you can specify an ordinary filesystem location for c3p0's configuration file via the system property com.mchange.v2.c3p0.cfg.xml.

意思是配置文件必须放在classpath路径中,在web环境下就是classes,这个目录中也就是src中的java文件编译过来的,按照上面的说明试过了,还是不行,听说oschina使用c3p0做数据连接,求教大家,这个问题怎么解决?
加载中
0
红薯
红薯
就放在 classes 目录下,自动加载的哦
0
南院逍大王
南院逍大王

引用来自“红薯”的答案

就放在 classes 目录下,自动加载的哦
试过了,还是不行的啊~
0
tianpeng91
tianpeng91
@红薯 我现在也出现这个问题了额 ,我话在src下,现在配置是叫c3p0-server.xml,ComboPooledDataSource这个类getUser()为null,蛋疼了啊
tianpeng91
tianpeng91
该评论暂时无法显示,详情咨询 QQ 群:点此入群
红薯
红薯
我没用过这个配置文件,都是直接用程序来配置:)
0
Ryan-瑞恩
Ryan-瑞恩

import java.io.InputStream;
import java.util.Properties;


public class DBConfig
{
private static String db_congfig = "db_config.properties";

public static String DRIVERS = null;
public static String URL = null;
public static String USER = null;
public static String PASSWORD = null;

static 
{
Properties props = new Properties();
InputStream is = null;

try
{
is = ClassLoader.getSystemResourceAsStream(db_congfig);
props.load(is);
DRIVERS = props.getProperty("drivers");
URL = props.getProperty("url");
USER = props.getProperty("user");
PASSWORD = props.getProperty("password");
}
catch(Exception e)
{
e.printStackTrace();
}
}


}

我用的是Properties文件。



XML的话就用:

System.setProperty("com.mchange.v2.c3p0.cfg.xml","configs/c3p0-config.xml");  



参考这里:

http://blog.csdn.net/willability/article/details/8467515

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部