首先我们要明确使用的是ssh2框架,然而struts2是基于filter实现的那么在启动proxool的时候就不能够在用servlet来启动了! 于是我们就想到在初始化web容器的时候怎么让他一开始就加载呢? 我们查看tomcat的启动信息: starting servlet engine: apache tomcat
首先我们要明确使用的是ssh2框架,然而struts2是基于filter实现的那么在启动proxool的时候就不能够在用servlet来启动了!
于是我们就想到在初始化web容器的时候怎么让他一开始就加载呢?
我们查看tomcat的启动信息:
starting servlet engine: apache tomcat/6.0.13
2012-6-10 15:31:41 org.apache.catalina.core.applicationcontext log
信息: initializing spring root webapplicationcontext
2012-6-10 15:31:41 org.springframework.web.context.contextloader initwebapplicationcontext
信息: root webapplicationcontext: initialization started
最先启动的是spring容器,那么这样我们就可以将proxool的配置写在spring的配置文件中让它最先加载
如下:
这样只需要在sessionfactory加上datasource的引用即可如下:
这样就不在需要配置proxool的servlet启动了,例如:
servletconfigurator org.logicalcobwebs.proxool.configuration.servletconfigurator xmlfile web-inf/classes/proxool.xml 1
以上的配置就不在需要在web.xml中进行配置。
而在hibernate.cfg.xml中也不在需要proxool的配置只是配置一些hibernate的信息例如:
trueorg.hibernate.dialect.mysqldialect
和一些实体类的映射文件:
以上就将ssh2+proxool的环境搭建好了。
但是在搭建好之后如果我们配置
又会提示如下错误:
invalid property 'housekeepingsleeptime' of bean class [org.logicalcobwebs.proxool.proxooldatasource]: bean property 'housekeepingsleeptime' is not writable or has an invalid setter method. does the parameter type of the setter match the return type of the getter?
大概意思是说'housekeepingsleeptime'属性是不能够写的或者没有合适的setter方法。在他的参数setter和getter的返回结果类型不一致所导致的。
这个我想也正是他的bug吧。
那么具体解决如下:
在proxool-0.9.1.jar(我用的proxool架包)中找到org.logicalcobwebs.proxool.proxooldatasource将其源码修改如下:
源码是:
1./** 2. * @see connectionpooldefinitionif#gethousekeepingsleeptime 3. */ 4. public long gethousekeepingsleeptime() { 5. return housekeepingsleeptime; 6. } 7. 8. /** 9. * @see connectionpooldefinitionif#gethousekeepingsleeptime 10. */ 11. public void sethousekeepingsleeptime(int housekeepingsleeptime) { 12. this.housekeepingsleeptime = housekeepingsleeptime; 13. }
修改为:
/** * @see connectionpooldefinitionif#gethousekeepingsleeptime */ public long gethousekeepingsleeptime() { return housekeepingsleeptime; } /** * @see connectionpooldefinitionif#gethousekeepingsleeptime *此处将int类型改为long类型 */ public void sethousekeepingsleeptime(long housekeepingsleeptime) { this.housekeepingsleeptime = housekeepingsleeptime; }
这样所有问题都解决!
以上所有步骤都是通过本人在网上查资料,自己手动配置而成。验证通过!