Fehler beim instanziieren SLF4J LoggerFactory
So,
Arbeite ich von zu in diesem Beispiel BONECP:
package javasampleapps;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;
/** A test project demonstrating the use of BoneCP in a JDBC environment.
* @author wwadge
*/
public class BoneCPExample {
/** Start test
* @param args none expected.
*/
public static void main(String[] args) {
BoneCP connectionPool = null;
Connection connection = null;
try {
// load the database driver (make sure this is in your classpath!)
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
e.printStackTrace();
return;
}
try {
// setup the connection pool
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl("jdbc:mysql://domain/db");
config.setUsername("root");
config.setPassword("pass");
config.setMinConnectionsPerPartition(5);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
connectionPool = new BoneCP(config); // setup the connection pool
connection = connectionPool.getConnection(); // fetch a connection
if (connection != null){
System.out.println("Connection successful!");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT id from batches limit 1"); // do something with the connection.
while(rs.next()){
System.out.println(rs.getString(1)); // should print out "1"'
}
}
connectionPool.shutdown(); // shutdown connection pool.
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
Fügte ich slf4j in meinen Bibliotheken-Menü in netbeans hinzufügen
D:/Documents%20and%20Settings/DavidH/My%20Documents/NetBeansProjects/jars/slf4j-api-1.6.4.jar
und
D:/Documents%20and%20Settings/DavidH/My%20Documents/NetBeansProjects/jars/slf4j-log4j12-1.6.4.jar
um die Bibliothek.
Dann machte ich eine Google Guava library Hinzugefügt und das Glas, dass Sie verteilen für die, die in einer anderen Bibliothek.
Ich habe dann Hinzugefügt, sowohl der Bibliotheken zum Projekt und hit run.
Bekomme ich jetzt diese Fehlermeldung:
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)
at com.jolbox.bonecp.BoneCPConfig.<clinit>(BoneCPConfig.java:60)
at javasampleapps.BoneCPExample.main(BoneCPExample.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 7 more
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)
at com.jolbox.bonecp.BoneCPConfig.<clinit>(BoneCPConfig.java:60)
at javasampleapps.BoneCPExample.main(BoneCPExample.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 7 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Was kann ich tun um dies zu beheben?
möglich, Duplikat der Fehler beim instanziieren SLF4J LoggerFactory in netbeans
InformationsquelleAutor davidahines | 2011-12-05
Du musst angemeldet sein, um einen Kommentar abzugeben.
Wenn Sie slf4j-log4j12-1.6.4.jar dann müssen Sie auch das log4j-jar. Slf4j ist eine logging-Fassade, das heißt, es gibt Sie, die eine einheitliche Schnittstelle zu mehreren anderen logging-APIs.
Die slf4j-log4j12 bietet die Umstellung auf die log4j-API. Da Sie nicht über die log4j-Bibliothek, wirft es einen Fehler. Nicht einschließlich die slf4j-log4j12 Bibliothek sollte ausreichen (wenn nur die slf4j-api-Bibliothek enthalten ist, dann sollte es dann standardmäßig eine no-operation-logger AFAIK).
InformationsquelleAutor Mark Rotteveel