gpt4 book ai didi

java - Amazon ec2 找不到 org.apache.tomcat.dbcp.dbcp.BasicDataSource

转载 作者:行者123 更新时间:2023-11-28 22:55:45 27 4
gpt4 key购买 nike

我正在尝试使用以下代码连接到 MySQL 服务,但它无法初始化数据库类:

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

public class Database {

private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
private static final BasicDataSource dataSource = new BasicDataSource();

static {
dataSource.setDriverClassName(JDBC_DRIVER);
dataSource.setUrl(ServerConfig.DB_URL);
dataSource.setUsername(ServerConfig.DB_USERNAME);
dataSource.setPassword(ServerConfig.DB_PASSWORD);
}

...
}

这是 ServerConfig 类:

public class ServerConfig {

public static final String DB_URL = "jdbc:mysql://localhost:3306/relay";
public static final String DB_USERNAME = "my_username";
public static final String DB_PASSWORD = "mypassword";

public static final boolean DEBUG = true;
}

这是堆栈跟踪:

java.lang.NoClassDefFoundError: Could not initialize class com.relayapp.server.database.Database
at com.relayapp.server.model.User.add(User.java:125)
at com.relayapp.server.request.AddUser.processRequest(AddUser.java:51)
at com.relayapp.server.request.RelayRequestServlet.doPost(RelayRequestServlet.java:55)
at com.relayapp.server.request.RelayRequestServlet.doGet(RelayRequestServlet.java:22)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)

用户凭据似乎是正确的,我可以成功运行 mysql 命令。我做错了什么?

最佳答案

问题出在 org.apache.tomcat.dbcp.dbcp.BasicDataSource 包上。

This answer帮助修复它。而不是 /usr/share/java 文件夹,tomcat 在 usr/share/tomcat7 文件夹中,我运行了命令:

sudo wget -O /usr/share/tomcat7/tomcat-dbcp-7.0.57.jar http://search.maven.org/remotecontent?filepath=org/apache/tomcat/tomcat-dbcp/7.0.57/7tomcat-dbcp-7.0.57.jar

关于java - Amazon ec2 找不到 org.apache.tomcat.dbcp.dbcp.BasicDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27675315/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com