Spring Boot 和 Heroku 上的 GET/POST 后如何解决 503(服务不可用)? [英] How can resolve 503 (Service Unavailable) after GET/POST on Spring Boot and Heroku?

查看:82
本文介绍了Spring Boot 和 Heroku 上的 GET/POST 后如何解决 503(服务不可用)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Heroku 上部署了我的 Spring Boot 应用程序,并且构建成功.但是,当我尝试从 Postman 到达终点时,我得到 503 Service Unavailable

I have deployed my Spring Boot application on Heroku, and the build is succeeded. However, when I try to hit the end-points from the Postman, I get the 503 Service Unavailable

而且,我检查了 Heroku 日志,下面的日志显示了应用程序被粉碎的位置

And, I inspect the Heroku logs and the bellow log shows where the app was crushed

2020-06-05T17:09:50.000000+00:00 app[api]: Build succeeded
2020-06-05T17:09:53.277483+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=17183 $JAVA_OPTS -jar target/ecommerce-0.0.1-SNAPSHOT.jar`
2020-06-05T17:09:55.407426+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-06-05T17:09:55.411915+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-06-05T17:09:55.581646+00:00 app[web.1]: no main manifest attribute, in target/ecommerce-0.0.1-SNAPSHOT.jar
2020-06-05T17:09:55.622586+00:00 heroku[web.1]: Process exited with status 1
2020-06-05T17:09:55.664598+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-05T17:10:16.658626+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/api/v1/item" host=xxx.com request_id=zz fwd="80.152.42.430" dyno= connect= service= status=503 bytes= protocol=https
2020-06-05T17:10:31.186284+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/api/v1/authenticate" host=xxx.com request_id=yy fwd="80.152.42.430" dyno= connect= service= status=503 bytes= protocol=https

请注意,在我对端点应用安全性之前,应用程序运行良好而不会崩溃.下面的代码显示了我如何配置受保护和不受保护的端点.当我尝试访问受保护或不受保护的端点时,应用程序会崩溃.在我看来 Heroku 不喜欢硬编码路径.这是给出路径的正确方法吗?

Please note that, the application was working fine without crushing until I have applied security on the end-points. The bellow code shows how I configured the protected and unprotected end-points. The app crushes when I try to hit the endpoints whether is protected or unprotected. It seems to me that Heroku does not like the hard coded paths. Is this the correct way to give paths?

顺便说一下,该应用在本地运行良好.

By the way, the app works fine locally.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .csrf()
            .disable()
            .authorizeRequests()
            .antMatchers("/api/v1/authenticate", "/api/v1/user/registration")
            .permitAll()
            .antMatchers( "/api/v1/item", "/api/v1/item/*")
            .permitAll()
            .anyRequest()
            .authenticated()
            .and()
            .exceptionHandling()
            .and()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
}

Procfile

web: java $JAVA_OPTS -jar target/ecommerce-0.0.1-SNAPSHOT.jar -Dserver.port=$PORT

更新

这是我在 Postman 上看到的回复:

This is what I see on Postman as response:

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
    <title>Application Error</title>
    <style media="screen">
        html,
        body,
        iframe {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            height: 100%;
            overflow: hidden;
        }

        iframe {
            width: 100%;
            height: 100%;
            border: 0;
        }
    </style>
</head>

<body>
    <iframe src="//www.herokucdn.com/error-pages/application-error.html"></iframe>
</body>

</html>

推荐答案

日志在第 5 行没有显示 main manifest 属性,可以使用

Logs are showing no main manifest attribute on line 5, which can be resolved by using

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

最初回答这里

这篇关于Spring Boot 和 Heroku 上的 GET/POST 后如何解决 503(服务不可用)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆