SSH2+proxool 出现No suitable driver found for proxool.mysqlProxool

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: SSH2+proxool 出现No suitable driver found for proxool.mysqlProxool  首先我们要明确使用的是SSH2框架,然而Struts2是基于filter实现的那么在启动proxool的时候就不能够在用servlet来启动了!于是我们就想到...

SSH2+proxool 出现No suitable driver found for proxool.mysqlProxool

 

首先我们要明确使用的是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的配置文件中让它最先加载

如下:

[html] view plain copy
  1. <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">    
  2.     <property name="alias" value="mysqlProxool"/>  
  3.     <property name="driver" value="com.mysql.jdbc.Driver"/>  
  4.     <property name="driverUrl" value="jdbc:mysql://localhost:3306/my_blog_01?characterEncoding=UTF-8"/>  
  5.     <property name="user" value="root"/>  
  6.     <property name="password" value="123456"/>  
  7.     <property name="minimumConnectionCount" value="2"/>  
  8.     <property name="maximumConnectionCount" value="10"/>  
  9.     <property name="prototypeCount" value="5"/>  
  10.     <!-- <property name="houseKeepingSleepTime" value="100000"/> -->  
  11.             </bean>  

这样只需要在sessionFactory加上dataSource的引用即可如下:

[html] view plain copy
  1.     <bean id="sessionFactory"  
  2.                 class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  3.                 <property name="configLocation" value="classpath:Hibernate.cfg.xml"/>  
  4.                 <span style="color:#ff0000;"><property name="dataSource">  
  5.                     <ref local="dataSource"/>  
  6.                 </property>  
  7. </span>           </bean>  

这样就不在需要配置proxool的servlet启动了,例如:

[html] view plain copy
  1.   <servlet>     
  2.         <servlet-name>ServletConfigurator</servlet-name>     
  3.         <servlet-class>     
  4.             org.logicalcobwebs.proxool.configuration.ServletConfigurator     
  5.         </servlet-class>     
  6.         <init-param>     
  7.             <param-name>xmlFile</param-name>     
  8.             <param-value>WEB-INF/classes/proxool.xml</param-value>     
  9.         </init-param>     
  10.         <load-on-startup>1</load-on-startup>     
  11.   </servlet>  
  12.    
[html] view plain copy
  1. 以上的配置就不在需要在web.xml中进行配置。  
[html] view plain copy
  1. 而在hibernate.cfg.xml中也不在需要proxool的配置只是配置一些hibernate的信息例如:  
[html] view plain copy
    1. <pre class="html" name="code">  <property name="show_sql">true</property>  
    2.     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property></pre><pre class="html" name="code">和一些实体类的映射文件:</pre><pre class="html" name="code"<mapping resource="com/wuda/hibernate/table/users.hbm.xml"/></pre><pre class="html" name="code">以上就将SSH2+PROXOOL的环境搭建好了。</pre><pre class="html" name="code"</pre><pre class="html" name="code">但是在搭建好之后如果我们配置<property name="houseKeepingSleepTime" value="100000"/></pre><pre class="html" name="code"</pre><pre class="html" name="code"</pre><pre class="html" name="code">又会提示如下错误:</pre><pre class="html" name="code">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?</pre><pre class="html" name="code">大概意思是说'houseKeepingSleepTime'属性是不能够写的或者没有合适的setter方法。在他的参数setter和getter的返回结果类型不一致所导致的。</pre><pre class="html" name="code">这个我想也正是他的bug吧。</pre><pre class="html" name="code">那么具体解决如下:</pre><pre class="html" name="code">在proxool-0.9.1.jar(我用的proxool架包)中找到org.logicalcobwebs.proxool.ProxoolDataSource将其源码修改如下:</pre><pre class="html" name="code"</pre><pre class="html" name="code">源码是:</pre><pre class="java" name="code">1./**    
    3. 2.    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime    
    4. 3.    */    
    5. 4.   public long getHouseKeepingSleepTime() {     
    6. 5.       return houseKeepingSleepTime;     
    7. 6.   }     
    8. 7.    
    9. 8.   /**    
    10. 9.    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime    
    11. 10.    */    
    12. 11.   public void setHouseKeepingSleepTime(int houseKeepingSleepTime) {     
    13. 12.       this.houseKeepingSleepTime = houseKeepingSleepTime;     
    14. 13.   }    
    15. </pre>  
    16. <pre></pre>  
    17. <pre class="html" name="code"</pre><pre class="html" name="code">修改为:</pre><pre class="html" name="code"><ol class="dp-j"><li><span><span class="comment">/** </span</span></li><li><span><span class="comment">    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime </span</span></li><li><span><span class="comment">    */</span><span>  </span></span></li><li><span>   </span><span class="keyword">public</span><span</span><span class="keyword">long</span><span> getHouseKeepingSleepTime() {   </span></li><li><span>       </span><span class="keyword">return</span><span> houseKeepingSleepTime;   </span></li><li><span>   }   </span></li><li><span>  </span></li><li><span>   </span><span class="comment">/** </span> </li><li><span><span class="comment">    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime </span> </span></li><li><span><span class="comment">    *此处将int类型改为long类型 </span> </span></li><li><span><span class="comment">    */</span><span>  </span></span></li><li><span>   </span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> setHouseKeepingSleepTime(</span><span class="keyword">long</span><span> houseKeepingSleepTime) {   </span></li><li><span>       </span><span class="keyword">this</span><span>.houseKeepingSleepTime = houseKeepingSleepTime;   </span></li><li><span>   }  </span></li></ol></pre><pre class="html" name="code">这样所有问题都解决!  
    18. </pre><pre class="html" name="code">以上所有步骤都是通过本人在网上查资料,自己手动配置而成。验证通过!</pre><pre class="html" name="code"</pre><pre class="html" name="code"</pre><pre class="html" name="code"</pre>  
    19. <pre></pre>  
    20.     
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
28天前
|
Java 数据库 Spring
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
17 0
|
1月前
|
Java 数据库连接 Spring
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could
这个错误通常出现在使用Spring Boot进行数据库连接时。错误信息表明Spring Boot未能配置一个DataSource,因为没有指定'url'属性,并且没有发现默认的数据库连接。
31 0
|
29天前
|
Java 数据库
SpringBoot出现com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime va
SpringBoot出现com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime va
15 0
|
5月前
|
SQL
报错org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column ‘xxx‘ from resu
报错org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column ‘xxx‘ from resu
159 0
报错org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column ‘xxx‘ from resu
|
6月前
|
Java 数据库连接 数据库
【Java异常】Failed to determine a suitable driver class
【Java异常】Failed to determine a suitable driver class
184 0
|
8月前
|
关系型数据库 MySQL Java
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
这个时候我们就要检查一下我们链接数据库的**url、root、password、**驱动是否正确,经过我的排查原来是我的url链接名不是localhost,真尴尬,改成localhost就成功了。
146 0
|
10月前
|
关系型数据库 MySQL Java
9. 成功解决:Driver class 'org.gjt.mm.mysql.Driver' could not be found
在使用 Kettle(Spoon) 工具创建 MySQL 数据库连接时,提示:Driver class 'org.gjt.mm.mysql.Driver' could not be found, make sure the 'MySQL' driver (jar file) is installed. org.gjt.mm.mysql.Driver
893 0
|
SQL 关系型数据库 MySQL
org.springframework.jdbc.BadSqlGrammarException: Error updating database
org.springframework.jdbc.BadSqlGrammarException: Error updating database
144 0
|
关系型数据库 MySQL Java
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
212 0
|
数据库
Failed to configure a DataSource: url attribute is not specified and no embedded datasource could...
Failed to configure a DataSource: url attribute is not specified and no embedded datasource could...
Failed to configure a DataSource: url attribute is not specified and no embedded datasource could...