- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了这个异常:
java.lang.ClassNotFoundException: com.p6spy.engine.spy.P6SpyDriver
尝试通过 P6Spy 代理驱动程序连接到我的数据库时。这个异常指向这行代码:
Class.forName("com.p6spy.engine.spy.P6SpyDriver");
我将P6Spy.jar和spy.properties添加到构建路径中,这是spy.properties配置文件:
#################################################################
# P6Spy Options File #
# See documentation for detailed instructions #
#################################################################
#################################################################
# MODULES #
# #
# Modules provide the P6Spy functionality. If a module, such #
# as module_log is commented out, that functionality will not #
# be available. If it is not commented out (if it is active), #
# the functionality will be active. #
# #
# Values set in Modules cannot be reloaded using the #
# reloadproperties variable. Once they are loaded, they remain #
# in memory until the application is restarted. #
# #
#################################################################
#module.log=com.p6spy.engine.logging.P6LogFactory
#module.outage=com.p6spy.engine.outage.P6OutageFactory
#################################################################
# REALDRIVER(s) #
# #
# In your application server configuration file you replace the #
# "real driver" name with com.p6spy.engine.P6SpyDriver. This is #
# where you put the name of your real driver P6Spy can find and #
# register your real driver to do the database work. #
# #
# If your application uses several drivers specify them in #
# realdriver2, realdriver3. See the documentation for more #
# details. #
# #
# Values set in REALDRIVER(s) cannot be reloaded using the #
# reloadproperties variable. Once they are loaded, they remain #
# in memory until the application is restarted. #
# #
#################################################################
# oracle driver
realdriver=oracle.jdbc.driver.OracleDriver
# mysql Connector/J driver
# realdriver=com.mysql.jdbc.Driver
# informix driver
# realdriver=com.informix.jdbc.IfxDriver
# ibm db2 driver
# realdriver=COM.ibm.db2.jdbc.net.DB2Driver
# the mysql open source driver
#realdriver=org.gjt.mm.mysql.Driver
#specifies another driver to use
#realdriver2=
#specifies a third driver to use
#realdriver3=
#the DriverManager class sequentially tries every driver that is
#registered to find the right driver. In some instances, it's possible to
#load up the realdriver before the p6spy driver, in which case your connections
#will not get wrapped as the realdriver will "steal" the connection before
#p6spy sees it. Set the following property to "true" to cause p6spy to
#explicitily deregister the realdrivers
deregisterdrivers=false
################################################################
# P6LOG SPECIFIC PROPERTIES #
################################################################
# no properties currently available
################################################################
# EXECUTION THRESHOLD PROPERTIES #
################################################################
# This feature applies to the standard logging of P6Spy. #
# While the standard logging logs out every statement #
# regardless of its execution time, this feature puts a time #
# condition on that logging. Only statements that have taken #
# longer than the time specified (in milliseconds) will be #
# logged. This way it is possible to see only statements that #
# have exceeded some high water mark. #
# This time is reloadable. #
#
# executionthreshold=integer time (milliseconds)
#
#executionthreshold=
################################################################
# P6OUTAGE SPECIFIC PROPERTIES #
################################################################
# Outage Detection
#
# This feature detects long-running statements that may be indicative of
# a database outage problem. If this feature is turned on, it will log any
# statement that surpasses the configurable time boundary during its execution.
# When this feature is enabled, no other statements are logged except the long
# running statements. The interval property is the boundary time set in seconds.
# For example, if this is set to 2, then any statement requiring at least 2
# seconds will be logged. Note that the same statement will continue to be logged
# for as long as it executes. So if the interval is set to 2, and the query takes
# 11 seconds, it will be logged 5 times (at the 2, 4, 6, 8, 10 second intervals).
#
# outagedetection=true|false
# outagedetectioninterval=integer time (seconds)
#
outagedetection=false
#outagedetectioninterval=
################################################################
# COMMON PROPERTIES #
################################################################
# filter what is logged
filter=false
# comma separated list of tables to include when filtering
include =
# comma separated list of tables to exclude when filtering
exclude =
# sql expression to evaluate if using regex filtering
#sqlexpression =
# turn on tracing
#autoflush = true
# sets the date format using Java's SimpleDateFormat routine
dateformat=yyyy-MM-dd
#list of categories to explicitly include
#includecategories=
#list of categories to exclude: error, info, batch, debug, statement,
#commit, rollback and result are valid values
excludecategories=
#allows you to use a regex engine or your own matching engine to determine
#which statements to log
#
#stringmatcher=com.p6spy.engine.common.GnuRegexMatcher
#stringmatcher=com.p6spy.engine.common.JakartaRegexMatcher
#stringmatcher=
# prints a stack trace for every statement logged
stacktrace=false
# if stacktrace=true, specifies the stack trace to print
#stacktraceclass=
# determines if property file should be reloaded
#reloadproperties=false
# determines how often should be reloaded in seconds
#reloadpropertiesinterval=60
#if=true then url must be prefixed with p6spy:
useprefix=true
#specifies the appender to use for logging
#appender=com.p6spy.engine.logging.appender.Log4jLogger
#appender=com.p6spy.engine.logging.appender.StdoutLogger
appender=com.p6spy.engine.logging.appender.FileLogger
# name of logfile to use, note Windows users should make sure to use forward slashes in their pathname (e:/test/spy.log) (used for file logger only)
logfile = D:/spy.log
# append to the p6spy log file. if this is set to false the
# log file is truncated every time. (file logger only)
append=true
#The following are for log4j logging only
#log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
#log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
#log4j.appender.STDOUT.layout.ConversionPattern=p6spy - %m%n
#log4j.appender.CHAINSAW_CLIENT=org.apache.log4j.net.SocketAppender
#log4j.appender.CHAINSAW_CLIENT.RemoteHost=localhost
#log4j.appender.CHAINSAW_CLIENT.Port=4445
#log4j.appender.CHAINSAW_CLIENT.LocationInfo=true
#log4j.logger.p6spy=INFO,STDOUT
#################################################################
# DataSource replacement #
# #
# Replace the real DataSource class in your application server #
# configuration with the name com.p6spy.engine.spy.P6DataSource,#
# then add the JNDI name and class name of the real #
# DataSource here #
# #
# Values set in this item cannot be reloaded using the #
# reloadproperties variable. Once it is loaded, it remains #
# in memory until the application is restarted. #
# #
#################################################################
#realdatasource=/RealMySqlDS
#realdatasourceclass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
#################################################################
# DataSource properties #
# #
# If you are using the DataSource support to intercept calls #
# to a DataSource that requires properties for proper setup, #
# define those properties here. Use name value pairs, separate #
# the name and value with a semicolon, and separate the #
# pairs with commas. #
# #
# The example shown here is for mysql #
# #
#################################################################
#realdatasourceproperties=port;3306,serverName;ibmhost,databaseName;mydb
#################################################################
# JNDI DataSource lookup #
# #
# If you are using the DataSource support outside of an app #
# server, you will probably need to define the JNDI Context #
# environment. #
# #
# If the P6Spy code will be executing inside an app server then #
# do not use these properties, and the DataSource lookup will #
# use the naming context defined by the app server. #
# #
# The two standard elements of the naming environment are #
# jndicontextfactory and jndicontextproviderurl. If you need #
# additional elements, use the jndicontextcustom property. #
# You can define multiple properties in jndicontextcustom, #
# in name value pairs. Separate the name and value with a #
# semicolon, and separate the pairs with commas. #
# #
# The example shown here is for a standalone program running on #
# a machine that is also running JBoss, so the JDNI context #
# is configured for JBoss (3.0.4). #
# #
#################################################################
#jndicontextfactory=org.jnp.interfaces.NamingContextFactory
#jndicontextproviderurl=localhost:1099
#jndicontextcustom=java.naming.factory.url.pkgs;org.jboss.nameing:org.jnp.interfaces
#jndicontextfactory=com.ibm.websphere.naming.WsnInitialContextFactory
#jndicontextproviderurl=iiop://localhost:900
append=true
这是我的连接类:
public class ConnexionBD {
private static final ConnexionBD INSTANCE= new ConnexionBD();
private String host;
private String database;
private int port;
private String login;
private char[] password;
private String privileges;
private Connection connection;
public static final String DATABASE_JDBC_DRIVER = "com.p6spy.engine.spy.P6SpyDriver";
private ConnexionBD() {}
public static ConnexionBD getInstance() {
return INSTANCE;
}
//getters and setters...
public Connection getConnection() throws ClassNotFoundException, SQLException {
String DATABASE_URL=null;
DATABASE_URL = "p6spy:jdbc:oracle:thin:@"+getHost()+":"+getPort()+":"+getDatabase();
if (connection!=null)
{
return connection ;
}
else{
Class.forName(DATABASE_JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,getLogin(),new String(getPassword())) ;
return connection ;
}
}
public void setConnection(Connection connection) {
this.connection = connection;
}
}
有人可以告诉我这里出了什么问题吗?非常感谢任何帮助!
最佳答案
看起来 P6SpyDriver 在运行时不在您的类路径中。语句 Class.forName(DATABASE_JDBC_DRIVER);
尝试使用与加载 ConnexionBD 相同的类加载器来加载 P6SpyDriver。无论出于何种原因,该类加载器无权访问该类。
我建议记录向类加载器及其父级注册的 URL。这可能会让您了解为什么会发生这种情况。请参阅下面的代码,了解如何记录类路径位置的示例。只需将方法添加到您的 ConnexionBD 类中,并在 Class.forName(DATABASE_JDBC_DRIVER);
上方的行添加 logClassPath(this);
即可。
private void logClassPath(final Class clazz) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ClassLoader cl = clazz.getClassLoader();
pw.println("Processing classloader which loaded " + clazz.getName() +" classloader: "+cl.getClass().getName());
if (cl instanceof URLClassLoader) {
logUrls(pw, (URLClassLoader) cl);
} else {
pw.println("Unsupported classloader - " + cl.getClass().getName());
}
while (cl.getParent() != null) {
cl = cl.getParent();
pw.println("\n\nProcessing parent classloader" +" classloader: "+cl.getClass().getName());
if (cl instanceof URLClassLoader) {
logUrls(pw, (URLClassLoader) cl);
} else {
pw.println("Unsupported classloader - " + cl.getClass().getName());
}
}
pw.flush();
System.out.print(sw.toString());
}
private void logUrls(final PrintWriter pw, final URLClassLoader cl) {
if( cl.getURLs().length == 0 ) {
pw.println("No URLs registered for this classloader");
}
for (URL url : cl.getURLs()) {
pw.println(url.toString());
}
}
我提供的代码仅适用于作为 URLClassloader 实例的类加载器。它还假设您也有分层类加载器。对于普通的 java 应用程序或在轻量级容器中运行的 Web 应用程序来说,这应该没问题。
如果您在基于 OSGI 的容器中运行,那么您将需要使用容器提供的任何工具来排除类加载故障。
关于java - 尝试记录 sql 请求时 P6Spy 出现 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24265827/
我正在尝试从该网站抓取历史天气数据: http://www.hko.gov.hk/cis/dailyExtract_uc.htm?y=2016&m=1 在阅读了 AJAX 调用后,我发现请求数据的正确
我有两个 postman 请求 x,y,它们命中了两个不同的休息 api X,Y 中的端点。 x 会给我一个身份验证 token ,这是发出 y 请求所必需的。如何在请求 y 中发出请求 x ?也就是
我使用请求库通过 API 与其他服务器进行通信。但现在我需要同时发送多个(10 个或更多)POST 请求,并且只有在所有响应都正确的情况下才能进一步前进。通常语法看起来有点像这样: var optio
背景:当用户单击按钮时,其类会在class1和class2之间切换,并且此数据是通过 AJAX 提交。为了确认此数据已保存,服务器使用 js 进行响应(更新按钮 HTML)。 问题:如果用户点击按钮的
我正在将 Node.js 中的请求库用于 Google 的文本转语音 API。我想打印出正在发送的请求,如 python example . 这是我的代码: const request = requi
我经常使用requests。最近我发现还有一个 requests2 和即将到来的 requests3 虽然有一个 page其中简要提到了 requests3 中的内容,我一直无法确定 requests
我正在尝试将图像发送到我的 API,然后从中获取结果。例如,我使用发送一个 bmp 图像文件 file = {"img": open("img.bmp)} r = requests.post(url,
我发现 Google Cloud 确保移出其物理环境的任何请求都经过强制加密,请参阅(虚拟机到虚拟机标题下的第 6 页)this link Azure(和 AWS)是否遵循类似的程序?如果有人能给我指
我有一个 ASP.NET MVC 应用程序,我正在尝试在 javascript 函数中使用 jQuery 来创建一系列操作。该函数由三部分组成。 我想做的是:如果满足某些条件,那么我想执行同步 jQu
我找不到如何执行 get http 请求,所以我希望你们能帮助我。 这个想法是从外部url(例如 https://api.twitter.com/1.1/search/tweets.json?q=tw
我的应用只需要使用“READ_SMS”权限。我的问题是,在 Android 6.0 上,当我需要使用新的权限系统时,它会要求用户“发送和查看短信”。 这是我的代码: ActivityCompat.re
我的前端代码: { this.searchInput = input; }}/> 搜索 // search method: const baseUrl = 'http://localho
我有一个由 AJAX 和 C# 应用程序使用的 WCF 服务, 我需要通过 HTTP 请求 header 发送一个参数。 在我的 AJAX 上,我添加了以下内容并且它有效: $.ajax({
我正在尝试了解如何使用 promises 编写代码。请检查我的代码。这样对吗? Node.js + 请求: request(url, function (error, response, body)
如果失败(除 HTTP 200 之外的任何响应代码),我需要重试发送 GWT RPC 请求。原因很复杂,所以我不会详细说明。到目前为止,我在同一个地方处理所有请求响应,如下所示: // We
当用户单击提交按钮时,我希望提交表单。然而,就在这种情况发生之前,我希望弹出一个窗口并让他们填写一些数据。一旦他们执行此操作并关闭该子窗口,我希望发出 POST 请求。 这可能吗?如果可能的话如何?我
像 Facebook 这样的网站使用“延迟”加载 js。当你必须考虑到我有一台服务器,流量很大时。 我很感兴趣 - 哪一个更好? 当我一次执行更多 HTTP 请求时 - 页面加载速度较慢(由于限制(一
Servlet 容器是否创建 ServletRequest 和 Response 对象或 Http 对象?如果是ServletRequest,谁在调用服务方法之前将其转换为HttpServletReq
这是维基百科文章的摘录: In contrast to the GET request method where only a URL and headers are sent to the serv
我有一个循环,每次循环时都会发出 HTTP post 请求。 for(let i = 1; i console.log("succes at " + i), error => con
我是一名优秀的程序员,十分优秀!