PersistenceManager 无法连接到数据库
PersistenceManager cannot connect to database
尝试 运行 使用 Jackrabbit 的应用程序(在本地 Tomcat7 上)时,无论出于何种原因,它都无法连接到数据库。使用相同凭据从常规 Java 应用程序连接到数据库。
如何调查连通性问题?有个问题Cannot instantiate persistence manager org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager
但没有解释。
数据库连接配置:
<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
<param name="driver" value="com.mysql.jdbc.Driver"/>
<param name="url" value="jdbc:mysql://localhost:3306/repo"/>
<param name="databaseType" value="mysql"/>
<param name="user" value="admin" />
<param name="password" value="password11.." />
<param name="schemaObjectPrefix" value="${wsp.name}_"/>
<param name="externalBLOBs" value="true"/>
</PersistenceManager>
错误输出:
[localhost-startStop-1] INFO org.apache.jackrabbit.core.RepositoryImpl - Starting repository...
[localhost-startStop-1] INFO org.apache.jackrabbit.core.fs.local.LocalFileSystem - LocalFileSystem initialized at path jackrabbit\repository
[localhost-startStop-1] INFO org.apache.jackrabbit.core.fs.local.LocalFileSystem - LocalFileSystem initialized at path jackrabbit\version
Tue Aug 21 10:46:47 CEST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
[localhost-startStop-1] ERROR org.apache.jackrabbit.core.RepositoryImpl - failed to start Repository: Cannot instantiate persistence manager org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager
javax.jcr.RepositoryException: Cannot instantiate persistence manager org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager
at org.apache.jackrabbit.core.RepositoryImpl.createPersistenceManager(RepositoryImpl.java:1379)
at org.apache.jackrabbit.core.RepositoryImpl.createVersionManager(RepositoryImpl.java:512)
at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:313)
at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:615)
at org.apache.jackrabbit.core.TransientRepository.getRepository(TransientRepository.java:250)
at org.apache.jackrabbit.core.TransientRepository.startRepository(TransientRepository.java:280)
at org.apache.jackrabbit.core.TransientRepository.login(TransientRepository.java:376)
at org.apache.jackrabbit.commons.AbstractRepository.login(AbstractRepository.java:144)
at org.omilab.services.repo.service.JackRabbitRepositoryProvider.<init>(JackRabbitRepositoryProvider.java:60)
at org.omilab.services.repo.service.JackRabbitRepositoryProvider.getInstance(JackRabbitRepositoryProvider.java:41)
at org.omilab.services.repo.service.JackRabbitConnector.<init>(JackRabbitConnector.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at codes.thischwa.c5c.ConnectorServlet.init(ConnectorServlet.java:79)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1282)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1195)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1085)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5318)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5610)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1092)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1984)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.apache.jackrabbit.core.util.db.ConnectionHelper.getExtraNameCharacters(ConnectionHelper.java:187)
at org.apache.jackrabbit.core.util.db.ConnectionHelper.prepareDbIdentifier(ConnectionHelper.java:142)
at org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager.init(BundleDbPersistenceManager.java:542)
at org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager.init(MySqlPersistenceManager.java:51)
at org.apache.jackrabbit.core.RepositoryImpl.createPersistenceManager(RepositoryImpl.java:1375)
... 33 more
编辑 1:
在使用同一个 Maven 构建的同一个 tomcat 上,这个简单的应用程序可以连接到同一个数据库:
<%@ page import="java.sql.*"%>
<html>
<head>
<title>DB</title>
</head>
<body>
<h1>DB connectivity test!</h1>
<%
String db = "repo";
String user = "admin";
String password = "password11..";
try {
java.sql.Connection con;
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/"+db, user, password);
out.println (db+ " database successfully opened.");
}
catch(SQLException e) {
out.println("SQLException caught: " +e.getMessage());
}
%>
</body>
我已经解决了这个问题。
Maven 正在附加到此应用程序的旧版本 mysql 连接器,该连接器本应兼容但无法正常工作。
尝试 运行 使用 Jackrabbit 的应用程序(在本地 Tomcat7 上)时,无论出于何种原因,它都无法连接到数据库。使用相同凭据从常规 Java 应用程序连接到数据库。 如何调查连通性问题?有个问题Cannot instantiate persistence manager org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager 但没有解释。
数据库连接配置:
<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
<param name="driver" value="com.mysql.jdbc.Driver"/>
<param name="url" value="jdbc:mysql://localhost:3306/repo"/>
<param name="databaseType" value="mysql"/>
<param name="user" value="admin" />
<param name="password" value="password11.." />
<param name="schemaObjectPrefix" value="${wsp.name}_"/>
<param name="externalBLOBs" value="true"/>
</PersistenceManager>
错误输出:
[localhost-startStop-1] INFO org.apache.jackrabbit.core.RepositoryImpl - Starting repository...
[localhost-startStop-1] INFO org.apache.jackrabbit.core.fs.local.LocalFileSystem - LocalFileSystem initialized at path jackrabbit\repository
[localhost-startStop-1] INFO org.apache.jackrabbit.core.fs.local.LocalFileSystem - LocalFileSystem initialized at path jackrabbit\version
Tue Aug 21 10:46:47 CEST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
[localhost-startStop-1] ERROR org.apache.jackrabbit.core.RepositoryImpl - failed to start Repository: Cannot instantiate persistence manager org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager
javax.jcr.RepositoryException: Cannot instantiate persistence manager org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager
at org.apache.jackrabbit.core.RepositoryImpl.createPersistenceManager(RepositoryImpl.java:1379)
at org.apache.jackrabbit.core.RepositoryImpl.createVersionManager(RepositoryImpl.java:512)
at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:313)
at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:615)
at org.apache.jackrabbit.core.TransientRepository.getRepository(TransientRepository.java:250)
at org.apache.jackrabbit.core.TransientRepository.startRepository(TransientRepository.java:280)
at org.apache.jackrabbit.core.TransientRepository.login(TransientRepository.java:376)
at org.apache.jackrabbit.commons.AbstractRepository.login(AbstractRepository.java:144)
at org.omilab.services.repo.service.JackRabbitRepositoryProvider.<init>(JackRabbitRepositoryProvider.java:60)
at org.omilab.services.repo.service.JackRabbitRepositoryProvider.getInstance(JackRabbitRepositoryProvider.java:41)
at org.omilab.services.repo.service.JackRabbitConnector.<init>(JackRabbitConnector.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at codes.thischwa.c5c.ConnectorServlet.init(ConnectorServlet.java:79)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1282)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1195)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1085)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5318)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5610)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1092)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1984)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.apache.jackrabbit.core.util.db.ConnectionHelper.getExtraNameCharacters(ConnectionHelper.java:187)
at org.apache.jackrabbit.core.util.db.ConnectionHelper.prepareDbIdentifier(ConnectionHelper.java:142)
at org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager.init(BundleDbPersistenceManager.java:542)
at org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager.init(MySqlPersistenceManager.java:51)
at org.apache.jackrabbit.core.RepositoryImpl.createPersistenceManager(RepositoryImpl.java:1375)
... 33 more
编辑 1:
在使用同一个 Maven 构建的同一个 tomcat 上,这个简单的应用程序可以连接到同一个数据库:
<%@ page import="java.sql.*"%>
<html>
<head>
<title>DB</title>
</head>
<body>
<h1>DB connectivity test!</h1>
<%
String db = "repo";
String user = "admin";
String password = "password11..";
try {
java.sql.Connection con;
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/"+db, user, password);
out.println (db+ " database successfully opened.");
}
catch(SQLException e) {
out.println("SQLException caught: " +e.getMessage());
}
%>
</body>
我已经解决了这个问题。 Maven 正在附加到此应用程序的旧版本 mysql 连接器,该连接器本应兼容但无法正常工作。