- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个 Web 应用程序,可以通过 maven eclipse 部署在 Heroku 上。
组 ID: org.glassfish.jersey.archetypes
工件 ID: jersey-heroku-webapp
版本:2.17
然后我按照这个指南(1.5)将其推送到 Heroku。
https://jersey.java.net/documentation/latest/getting-started.html#heroku-webapp
我无法从 http 链接访问我的 apple
类,如下所示:
https://salty-refuge-2027.herokuapp.com/apple
我收到错误500
我之前已经在没有 JDBC 过程的情况下测试过它,并且得到了输出 Hello, from apple class
因此我想这取决于我对 Heroku Postgres
的实现 https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-java
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("apple")
public class Apple {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getIt() {
try {
getConnection();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "Hello, from apple class";
}
private static Connection getConnection() throws URISyntaxException, SQLException {
//I have modified my orginal ingredients.
URI dbUri = new URI(System.getenv("postgres://mglfe545z6ixsgk:yf8gyK1hBh3jknzqepLnajWRLv@
ec2-60-16-433-222.compute-1.amazonaws.com:5432/d5kal1r7jtavr9"));
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':'
+ dbUri.getPort() + dbUri.getPath();
Connection con = DriverManager.getConnection(dbUrl, username, password);
System.out.println("It works");
return con;
}
}
Heroku 日志:
D:\maven\heroku_maven_by_eclipse\serverSide>heroku logs
2015-05-13T11:19:11.364893+00:00 app[web.1]: at org.glassfish.jersey.servlet.
WebComponent.service(WebComponent.java:401)
2015-05-13T11:19:11.364825+00:00 app[web.1]: at org.eclipse.jetty.security.Se
curityHandler.handle(SecurityHandler.java:564)
2015-05-13T11:19:11.364826+00:00 app[web.1]: at org.eclipse.jetty.server.sess
ion.SessionHandler.doHandle(SessionHandler.java:213)
2015-05-13T11:19:11.364828+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ContextHandler.doHandle(ContextHandler.java:1097)
2015-05-13T11:19:11.364895+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:386)
2015-05-13T11:19:11.364896+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:335)
2015-05-13T11:19:11.364846+00:00 app[web.1]: java.lang.NullPointerException
2015-05-13T11:19:11.364901+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ScopedHandler.handle(ScopedHandler.java:138)
2015-05-13T11:19:11.364898+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHolder.handle(ServletHolder.java:698)
2015-05-13T11:19:11.364900+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHandler.doHandle(ServletHandler.java:519)
2015-05-13T11:19:11.364902+00:00 app[web.1]: at org.eclipse.jetty.security.Se
curityHandler.handle(SecurityHandler.java:564)
2015-05-13T11:19:11.364904+00:00 app[web.1]: at org.eclipse.jetty.server.sess
ion.SessionHandler.doHandle(SessionHandler.java:213)
2015-05-13T11:19:11.364908+00:00 app[web.1]: at org.eclipse.jetty.server.sess
ion.SessionHandler.doScope(SessionHandler.java:175)
2015-05-13T11:19:11.364906+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHandler.doScope(ServletHandler.java:446)
2015-05-13T11:19:11.364909+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ContextHandler.doScope(ContextHandler.java:1031)
2015-05-13T11:19:11.364805+00:00 app[web.1]: 2015-05-13 11:19:11.364:WARN:oejs.S
ervletHandler:qtp688970022-21:
2015-05-13T11:19:11.364910+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ScopedHandler.handle(ScopedHandler.java:136)
2015-05-13T11:19:11.364911+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.HandlerWrapper.handle(HandlerWrapper.java:97)
2015-05-13T11:19:11.364913+00:00 app[web.1]: at org.eclipse.jetty.server.Serv
er.handle(Server.java:445)
2015-05-13T11:19:11.364916+00:00 app[web.1]: at org.eclipse.jetty.server.Http
Connection.onFillable(HttpConnection.java:229)
2015-05-13T11:19:11.364914+00:00 app[web.1]: at org.eclipse.jetty.server.Http
Channel.handle(HttpChannel.java:269)
2015-05-13T11:19:11.364917+00:00 app[web.1]: at org.eclipse.jetty.io.Abstract
Connection$ReadCallback.run(AbstractConnection.java:358)
2015-05-13T11:19:11.364905+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ContextHandler.doHandle(ContextHandler.java:1097)
2015-05-13T11:19:11.364938+00:00 app[web.1]: at org.eclipse.jetty.util.thread
.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
2015-05-13T11:19:11.364941+00:00 app[web.1]: at java.lang.Thread.run(Thread.j
ava:745)
2015-05-13T11:19:11.364940+00:00 app[web.1]: at org.eclipse.jetty.util.thread
.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
2015-05-13T11:19:11.366434+00:00 heroku[router]: at=info method=GET path="/apple
" host=salty-refuge-2027.herokuapp.com request_id=77099e48-00b0-4ac2-8c41-c631b9
619a63 fwd="31.17.41.138" dyno=web.1 connect=1ms service=5ms status=500 bytes=50
5
2015-05-13T11:19:12.339340+00:00 heroku[router]: at=info method=GET path="/apple
" host=salty-refuge-2027.herokuapp.com request_id=cb3396d8-474c-436c-9f13-a6d7a3
ac102e fwd="31.17.41.138" dyno=web.1 connect=1ms service=6ms status=500 bytes=50
5
2015-05-13T11:19:12.337223+00:00 app[web.1]: 2015-05-13 11:19:12.336:WARN:oejs.S
ervletHandler:qtp688970022-22:
2015-05-13T11:19:12.337244+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:222)
2015-05-13T11:19:12.337246+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHolder.handle(ServletHolder.java:698)
2015-05-13T11:19:12.337248+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHandler.doHandle(ServletHandler.java:519)
2015-05-13T11:19:12.337235+00:00 app[web.1]: javax.servlet.ServletException: jav
a.lang.NullPointerException
2015-05-13T11:19:12.337237+00:00 app[web.1]: at org.glassfish.jersey.servlet.
WebComponent.service(WebComponent.java:421)
2015-05-13T11:19:12.337240+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:386)
2015-05-13T11:19:12.337242+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:335)
2015-05-13T11:19:12.337259+00:00 app[web.1]: at org.eclipse.jetty.server.sess
ion.SessionHandler.doScope(SessionHandler.java:175)
2015-05-13T11:19:12.337250+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ScopedHandler.handle(ScopedHandler.java:138)
2015-05-13T11:19:12.337252+00:00 app[web.1]: at org.eclipse.jetty.security.Se
curityHandler.handle(SecurityHandler.java:564)
2015-05-13T11:19:12.337254+00:00 app[web.1]: at org.eclipse.jetty.server.sess
ion.SessionHandler.doHandle(SessionHandler.java:213)
2015-05-13T11:19:12.337256+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ContextHandler.doHandle(ContextHandler.java:1097)
2015-05-13T11:19:12.337257+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHandler.doScope(ServletHandler.java:446)
2015-05-13T11:19:12.337261+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ContextHandler.doScope(ContextHandler.java:1031)
2015-05-13T11:19:12.337263+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ScopedHandler.handle(ScopedHandler.java:136)
2015-05-13T11:19:12.337265+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.HandlerWrapper.handle(HandlerWrapper.java:97)
2015-05-13T11:19:12.337271+00:00 app[web.1]: at org.eclipse.jetty.server.Http
Connection.onFillable(HttpConnection.java:229)
2015-05-13T11:19:12.337272+00:00 app[web.1]: at org.eclipse.jetty.io.Abstract
Connection$ReadCallback.run(AbstractConnection.java:358)
2015-05-13T11:19:12.337274+00:00 app[web.1]: at org.eclipse.jetty.util.thread
.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
2015-05-13T11:19:12.337275+00:00 app[web.1]: at org.eclipse.jetty.util.thread
.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
2015-05-13T11:19:12.337277+00:00 app[web.1]: at java.lang.Thread.run(Thread.j
ava:745)
2015-05-13T11:19:12.337278+00:00 app[web.1]: Caused by:
2015-05-13T11:19:12.337269+00:00 app[web.1]: at org.eclipse.jetty.server.Http
Channel.handle(HttpChannel.java:269)
2015-05-13T11:19:12.337267+00:00 app[web.1]: at org.eclipse.jetty.server.Serv
er.handle(Server.java:445)
2015-05-13T11:19:12.337280+00:00 app[web.1]: java.lang.NullPointerException
2015-05-13T11:19:12.337281+00:00 app[web.1]: at java.net.URI$Parser.parse(URI
.java:3023)
2015-05-13T11:19:12.337293+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvo
cationHandlerFactory.java:81)
2015-05-13T11:19:12.337283+00:00 app[web.1]: at java.net.URI.<init>(URI.java:
595)
2015-05-13T11:19:12.337284+00:00 app[web.1]: at busTracker.serverSide.Apple.g
etConnection(Apple.java:34)
2015-05-13T11:19:12.337285+00:00 app[web.1]: at busTracker.serverSide.Apple.g
etIt(Apple.java:21)
2015-05-13T11:19:12.337290+00:00 app[web.1]: at sun.reflect.DelegatingMethodA
ccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2015-05-13T11:19:12.337295+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMet
hodDispatcher.java:164)
2015-05-13T11:19:12.337296+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMe
thodDispatcher.java:181)
2015-05-13T11:19:12.337287+00:00 app[web.1]: at sun.reflect.NativeMethodAcces
sorImpl.invoke0(Native Method)
2015-05-13T11:19:12.337288+00:00 app[web.1]: at sun.reflect.NativeMethodAcces
sorImpl.invoke(NativeMethodAccessorImpl.java:57)
2015-05-13T11:19:12.337291+00:00 app[web.1]: at java.lang.reflect.Method.invo
ke(Method.java:606)
2015-05-13T11:19:12.337300+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResource
MethodDispatcher.java:101)
2015-05-13T11:19:12.337308+00:00 app[web.1]: at org.glassfish.jersey.internal
.Errors$1.call(Errors.java:267)
2015-05-13T11:19:12.337310+00:00 app[web.1]: at org.glassfish.jersey.internal
.Errors.process(Errors.java:315)
2015-05-13T11:19:12.337311+00:00 app[web.1]: at org.glassfish.jersey.internal
.Errors.process(Errors.java:297)
2015-05-13T11:19:12.337301+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
2015-05-13T11:19:12.337303+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
2015-05-13T11:19:12.337304+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
2015-05-13T11:19:12.337306+00:00 app[web.1]: at org.glassfish.jersey.server.S
erverRuntime$2.run(ServerRuntime.java:305)
2015-05-13T11:19:12.337307+00:00 app[web.1]: at org.glassfish.jersey.internal
.Errors$1.call(Errors.java:271)
2015-05-13T11:19:12.337298+00:00 app[web.1]: at org.glassfish.jersey.server.m
odel.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(Jav
aResourceMethodDispatcherProvider.java:203)
2015-05-13T11:19:12.337330+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHolder.handle(ServletHolder.java:698)
2015-05-13T11:19:12.337332+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHandler.doHandle(ServletHandler.java:519)
2015-05-13T11:19:12.337326+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:386)
2015-05-13T11:19:12.337312+00:00 app[web.1]: at org.glassfish.jersey.internal
.Errors.process(Errors.java:267)
2015-05-13T11:19:12.337314+00:00 app[web.1]: at org.glassfish.jersey.process.
internal.RequestScope.runInScope(RequestScope.java:317)
2015-05-13T11:19:12.337337+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ContextHandler.doHandle(ContextHandler.java:1097)
2015-05-13T11:19:12.337333+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ScopedHandler.handle(ScopedHandler.java:138)
2015-05-13T11:19:12.337334+00:00 app[web.1]: at org.eclipse.jetty.security.Se
curityHandler.handle(SecurityHandler.java:564)
2015-05-13T11:19:12.337336+00:00 app[web.1]: at org.eclipse.jetty.server.sess
ion.SessionHandler.doHandle(SessionHandler.java:213)
2015-05-13T11:19:12.337315+00:00 app[web.1]: at org.glassfish.jersey.server.S
erverRuntime.process(ServerRuntime.java:288)
2015-05-13T11:19:12.337325+00:00 app[web.1]: at org.glassfish.jersey.servlet.
WebComponent.service(WebComponent.java:401)
2015-05-13T11:19:12.337339+00:00 app[web.1]: at org.eclipse.jetty.server.sess
ion.SessionHandler.doScope(SessionHandler.java:175)
2015-05-13T11:19:12.337316+00:00 app[web.1]: at org.glassfish.jersey.server.A
pplicationHandler.handle(ApplicationHandler.java:1110)
2015-05-13T11:19:12.337329+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:222)
2015-05-13T11:19:12.337341+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ContextHandler.doScope(ContextHandler.java:1031)
2015-05-13T11:19:12.337338+00:00 app[web.1]: at org.eclipse.jetty.servlet.Ser
vletHandler.doScope(ServletHandler.java:446)
2015-05-13T11:19:12.337342+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.ScopedHandler.handle(ScopedHandler.java:136)
2015-05-13T11:19:12.337344+00:00 app[web.1]: at org.eclipse.jetty.server.Serv
er.handle(Server.java:445)
2015-05-13T11:19:12.337343+00:00 app[web.1]: at org.eclipse.jetty.server.hand
ler.HandlerWrapper.handle(HandlerWrapper.java:97)
2015-05-13T11:19:12.337346+00:00 app[web.1]: at org.eclipse.jetty.server.Http
Channel.handle(HttpChannel.java:269)
2015-05-13T11:19:12.337350+00:00 app[web.1]: at org.eclipse.jetty.util.thread
.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
2015-05-13T11:19:12.337353+00:00 app[web.1]: at java.lang.Thread.run(Thread.j
ava:745)
2015-05-13T11:19:12.337349+00:00 app[web.1]: at org.eclipse.jetty.io.Abstract
Connection$ReadCallback.run(AbstractConnection.java:358)
2015-05-13T11:19:12.337347+00:00 app[web.1]: at org.eclipse.jetty.server.Http
Connection.onFillable(HttpConnection.java:229)
2015-05-13T11:19:12.337351+00:00 app[web.1]: at org.eclipse.jetty.util.thread
.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
2015-05-13T11:19:12.337328+00:00 app[web.1]: at org.glassfish.jersey.servlet.
ServletContainer.service(ServletContainer.java:335)
最佳答案
嗯,从日志来看。看来错误是这部分
URI dbUri = new URI(System.getenv("postgres://mglfe545z6ixsgk:yf8gyK1hBh3jknzqepLnajWRLv@ec2-60-16-433-222.compute-1.amazonaws.com:5432/d5kal1r7jtavr9"));
dbUri
变量为 null,因为应用程序找不到系统环境变量。也许这就是你的意思?
URI dbUri = new URI("postgres://mglfe545z6ixsgk:yf8gyK1hBh3jknzqepLnajWRLv@ec2-60-16-433-222.compute-1.amazonaws.com:5432/d5kal1r7jtavr9");
如果没有,您可能需要检查系统环境变量中是否有此 key postgres://mglfe545z6ixsgk:yf8gyK1hBh3jknzqepLnajWRLv@ec2-60-16-433-222.compute-1.amazonaws.com:5432/d5kal1r7jtavr9
虽然我认为拥有一个带有这样的键的环境变量是很荒谬的:p
编辑
来自文档。看来你的代码应该这样写
URI dbUri = new URI(System.getenv("DATABASE_URL"));
“DATABASE_URL”
是一个已设置到您的环境中的变量,因此它应该检索正确的值。你可能想在Linux系统上像这样检查它
echo $DATABASE_URL
或在 Windows 中
echo %DATABASE_URL%
关于java - 我无法连接 Heroku 上的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30213149/
我通过 spring ioc 编写了一些 Rest 应用程序。但我无法解决这个问题。这是我的异常(exception): org.springframework.beans.factory.BeanC
我对 TestNG、Spring 框架等完全陌生,我正在尝试使用注释 @Value通过 @Configuration 访问配置文件注释。 我在这里想要实现的目标是让控制台从配置文件中写出“hi”,通过
为此工作了几个小时。我完全被难住了。 这是 CS113 的实验室。 如果用户在程序(二进制计算器)结束时选择继续,我们需要使用 goto 语句来到达程序的顶部。 但是,我们还需要释放所有分配的内存。
我正在尝试使用 ffmpeg 库构建一个小的 C 程序。但是我什至无法使用 avformat_open_input() 打开音频文件设置检查错误代码的函数后,我得到以下输出: Error code:
使用 Spring Initializer 创建一个简单的 Spring boot。我只在可用选项下选择 DevTools。 创建项目后,无需对其进行任何更改,即可正常运行程序。 现在,当我尝试在项目
所以我只是在 Mac OS X 中通过 brew 安装了 qt。但是它无法链接它。当我尝试运行 brew link qt 或 brew link --overwrite qt 我得到以下信息: ton
我在提交和 pull 时遇到了问题:在提交的 IDE 中,我看到: warning not all local changes may be shown due to an error: unable
我跑 man gcc | grep "-L" 我明白了 Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more inf
我有一段代码,旨在接收任何 URL 并将其从网络上撕下来。到目前为止,它运行良好,直到有人给了它这个 URL: http://www.aspensurgical.com/static/images/a
在过去的 5 个小时里,我一直在尝试在我的服务器上设置 WireGuard,但在完成所有设置后,我无法 ping IP 或解析域。 下面是服务器配置 [Interface] Address = 10.
我正在尝试在 GitLab 中 fork 我的一个私有(private)项目,但是当我按下 fork 按钮时,我会收到以下信息: No available namespaces to fork the
我这里遇到了一些问题。我是 node.js 和 Rest API 的新手,但我正在尝试自学。我制作了 REST API,使用 MongoDB 与我的数据库进行通信,我使用 Postman 来测试我的路
下面的代码在控制台中给出以下消息: Uncaught DOMException: Failed to execute 'appendChild' on 'Node': The new child el
我正在尝试调用一个新端点来显示数据,我意识到在上一组有效的数据中,它在数据周围用一对额外的“[]”括号进行控制台,我认为这就是问题是,而新端点不会以我使用数据的方式产生它! 这是 NgFor 失败的原
我正在尝试将我的 Symfony2 应用程序部署到我的 Azure Web 应用程序,但遇到了一些麻烦。 推送到远程时,我在终端中收到以下消息 remote: Updating branch 'mas
Minikube已启动并正在运行,没有任何错误,但是我无法 curl IP。我在这里遵循:https://docs.traefik.io/user-guide/kubernetes/,似乎没有提到关闭
每当我尝试docker组成任何项目时,都会出现以下错误。 我尝试过有和没有sudo 我在这台机器上只有这个问题。我可以在Mac和Amazon WorkSpace上运行相同的容器。 (myslabs)
我正在尝试 pip install stanza 并收到此消息: ERROR: No matching distribution found for torch>=1.3.0 (from stanza
DNS 解析看起来不错,但我无法 ping 我的服务。可能是什么原因? 来自集群中的另一个 Pod: $ ping backend PING backend.default.svc.cluster.l
我正在使用Hibernate 4 + Spring MVC 4当我开始 Apache Tomcat Server 8我收到此错误: Error creating bean with name 'wel
我是一名优秀的程序员,十分优秀!