分享

JSP学习笔记(七十九):spring中使用jamon跟踪执行的sql语句 - 魔豆的BL...

 孙中熙——路 2010-12-07

一、获取jamon

jamon官方地址:http://jamonapi./

jamon下载地址:http:///project/showfiles.php?group_id=96550

二、部署jamon到项目中

解压下载的压缩包,压缩包里有一个例子jamon.war,在项目里新建一个文件夹jamon,该文件夹跟WEB-INF同级,把例子里除了WEB-INF,META-INF的所有内容copy到文件夹jamon里,添加例子中的三个包jakarta-oro-2.0.8.jar,hsqldb.jar,fdsapi-1.2.jar,压缩包中的jamon-2.7.jar到项目中。

三、把jamon集成到spring中

不使用jamon时,配置文件内容为:

    <bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value
="${jdbc.driverClassName}">
</property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>

使用jamon时,配置文件改为:

    <bean id="dataSource" class="com.abc.dao.jdbc.MonitorDataSource" destroy-method="close">   
<property name="realDataSource" ref="writeDataSource"/>
</bean>

<bean id="writeDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value
="${jdbc.driverClassName}">
</property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>

 

需要添加一个MonitorDataSource类,该类实现了javax.sql.DataSource接口

public class MonitorDataSource implements DataSource {

private DataSource realDataSource;

public Connection getConnection() throws SQLException {
return MonProxyFactory.monitor(realDataSource.getConnection());
}

public Connection getConnection(String arg0, String arg1)
throws SQLException {
return MonProxyFactory
.monitor(realDataSource.getConnection(arg0, arg1));
}

public PrintWriter getLogWriter() throws SQLException {
return null;
}

public int getLoginTimeout() throws SQLException {
return 0;
}

public void setLogWriter(PrintWriter arg0) throws SQLException {

}

public void setLoginTimeout(int arg0) throws SQLException {

}

public DataSource getRealDataSource() {
return realDataSource;
}

public void setRealDataSource(DataSource realDataSource) {
this.realDataSource = realDataSource;
}

}

 

四、查看执行的sql语句

打开 http://你的项目路径/jamon/sql.jsp 应该就可以看到该项目执行过的sql语句了

五、问题

一般的sql执行都没有问题,我碰到了一个特殊的情况,出现问题:Class com.jamonapi.proxy.MonProxy can not access a member of class oracle.jdbc.driver.ScrollRsetStatement with modifiers "public abstract"

不知道怎么去解决,或许是jamon的bug,还需要改进吧,郁闷,我的项目是没法使用jamon了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多