Proxool数据库连接池整合问题

Proxool数据库连接池整合问题

近期在整合struts2springhibernate,使用proxool配置数据库连接池总是报错,查找了下原因如下:

StrutsSpring整合时,spring必须以listener加载,而proxool是使用Servlet加载的。

这样就导致spring早于proxool加载,spring在创建datasourceproxool连接池还没加载,从而报错。在网上有牛人用如下方法解决

解决方案一:自己写监听器早于Spring加载proxool

<context-param>

<param-name>xmlFile</param-name>

<param-value>WEB-INF/classes/proxool-conf.xml</param-value>

</context-param>

<listener>

 <listener-class>sgwmis.web.listener.ProxoolListener</listener-class>

</listener>

 

public class ProxoolListener implements ServletContextListener {

private static final NetLogger log = NetLogger.getLogger(ProxoolListener.class);

private static final String XML_FILE_PROPERTY = "xmlFile";

private static final String PROPERTY_FILE_PROPERTY = "propertyFile";

private static final String AUTO_SHUTDOWN_PROPERTY = "autoShutdown";

 

private boolean autoShutdown = true;

 

@Override

public void contextDestroyed(ServletContextEvent contextEvent) {

if (autoShutdown) {

ProxoolFacade.shutdown(0);

}

}

 

@Override

public void contextInitialized(ServletContextEvent contextEvent) {

ServletContext context = contextEvent.getServletContext(); // 对应servletinit方法中ServletConfig.getServletContext()

String appDir = contextEvent.getServletContext().getRealPath("/");

Properties properties = new Properties();

 

Enumeration<String> names = context.getInitParameterNames();

while (names.hasMoreElements()) {

String name = (String) names.nextElement();

String value = context.getInitParameter(name);

 

if (name.equals(XML_FILE_PROPERTY)) {

try {

File file = new File(value);

if (file.isAbsolute()) {

JAXPConfigurator.configure(value, false);

else {

JAXPConfigurator.configure(appDir + File.separator

+ value, false);

}

catch (ProxoolException e) {

log.error("Problem configuring " + value, e);

}

else if (name.equals(PROPERTY_FILE_PROPERTY)) {

try {

File file = new File(value);

if (file.isAbsolute()) {

PropertyConfigurator.configure(value);

else {

PropertyConfigurator.configure(appDir + File.separator

+ value);

}

catch (ProxoolException e) {

log.error("Problem configuring " + value, e);

}

else if (name.equals(AUTO_SHUTDOWN_PROPERTY)) {

 autoShutdown = Boolean.valueOf(value).booleanValue();

else if (name.startsWith("jdbc")) { // 此处以前是PropertyConfigurator.PREFIX改为jdbc

properties.setProperty(name, value);

}

}

 

if (properties.size() > 0) {

try {

PropertyConfigurator.configure(properties);

catch (ProxoolException e) {

log.error("Problem configuring using init properties", e);

}

}

}

 

}

 

方法二:就是有spring完全管理proxool,这个网络上有很多,大家可以参考下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值