我正在尝试将我的webapp和数据库上传到CloudBees,但似乎我的数据库没有响应应用程序。我按照this视频上传了我的数据库和this视频,以上传我的网络应用程序。但仍然无效。
更新我发现了这个堆栈跟踪:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'ec2-23-21-211-172.compute-1.amazonaws.com'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at com.neu.als.thesis.utilities.DefaultValuesUtility.getQuestionsCount(DefaultValuesUtility.java:2069)
at com.neu.als.thesis.utilities.DefaultValuesUtility.checkDataBase(DefaultValuesUtility.java:2240)
at com.neu.als.thesis.web.controllers.DefaultController.index(DefaultController.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:444)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:432)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:946)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:680)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
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: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 38 more
这是我在CloudBees中的应用配置:
这是我在CloudBees中的数据库配置:
我的web.xml
<!-- Database resources -->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/testd</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
我的context.xml
:
<Context>
<Loader delegate="true" />
<Resource name="jdbc/testd" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="testus" password="password"
url="ec2-23-21-211-172.compute-1.amazonaws.com"
driverClassName="com.mysql.jdbc.Driver" />
</Context>
我的数据库连接类:
public final class DatabaseCommunication
{
public static DatabaseCommunication getInstance()
{
return DatabaseCommunicationHolder.INSTANCE;
}
/**
* private declaration of dataSource variable to avoid instanciation
*/
private DataSource dataSource;
/**
* @return returns data source instance
*/
public synchronized DataSource getDataSource() throws NamingException
{
if( dataSource == null )
{
InitialContext cxt = new InitialContext();
dataSource = ( DataSource ) cxt.lookup( "java:/comp/env/jdbc/testd" );
}
return dataSource;
}
private static class DatabaseCommunicationHolder
{
/**
* instanciates DatabaseCommunication
*/
public static final DatabaseCommunication INSTANCE = new DatabaseCommunication();
}
}
我在工作台中的设置:
密码为:password
我使用此命令绑定了我的数据库:
在我的本地,我能够从我的数据库登录帐户。但我不知道为什么在CloudBees中它没有。 bees app:bind -db testd -a demoproject -as testd
请帮帮我。
答案 0 :(得分:2)
好吧,我更愿意在你的datasource.xml文件
上使用它来与JNDI进行绑定<jee:jndi-lookup id="dataSource" jndi-name="jdbc/testdb" resource-ref="true"/>
您可以尝试不在context.xml文件中声明数据源。而不是那样,您将通过CloudBees SDK使用app:bind命令自动注入它。通过这种方式,您可以确保正确声明了数据源。
然后您应该删除context.xml文件的这一部分
<Resource name="jdbc/testd" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="testus" password="password"
url="ec2-23-21-211-172.compute-1.amazonaws.com"
driverClassName="com.mysql.jdbc.Driver" />
所以,它应该是这样的:
<Context>
<Loader delegate="true" />
</Context>
答案 1 :(得分:0)
资源URL必须是JDBC URL jdbc:mysql:ec2-23-21-211-172.compute-1.amazonaws.com:3306/database
,而不仅仅是服务器主机名