Mysql heroku上已部署springboot应用程序的问题

Mysql heroku上已部署springboot应用程序的问题,mysql,spring,spring-boot,heroku,cleardb,Mysql,Spring,Spring Boot,Heroku,Cleardb,我在Heroku上部署了一个springboot RestApi。当我通过在我的计算机上运行此项目时,我得到了期望的响应,如下所示: [ { "userId" : "ABC123XYZ", "sessionId" : "XYZ456ABC", "action" : [ { "time" : "2018-10-19T03:37:28.000+0000", "type" : "CLICK", "properties" : { "locationX" :

我在Heroku上部署了一个springboot RestApi。当我通过在我的计算机上运行此项目时,我得到了期望的响应,如下所示:

[ {
  "userId" : "ABC123XYZ",
  "sessionId" : "XYZ456ABC",
  "action" : [ {
    "time" : "2018-10-19T03:37:28.000+0000",
    "type" : "CLICK",
    "properties" : {
      "locationX" : null,
      "locationY" : null,
      "viewedId" : null,
      "pageFrom" : null,
      "pageTo" : null
    }
  }, {
    "time" : "2018-10-19T03:37:28.000+0000",
    "type" : "CLICK",
    "properties" : {
      "locationX" : null,
      "locationY" : null,
      "viewedId" : null,
      "pageFrom" : null,
      "pageTo" : null
    }
  }, {
    "time" : "2018-10-19T03:37:28.000+0000",
    "type" : "CLICK",
    "properties" : {
      "locationX" : null,
      "locationY" : null,
      "viewedId" : null,
      "pageFrom" : null,
      "pageTo" : null
    }
  }, {
    "time" : "2018-10-19T03:37:30.000+0000",
    "type" : "VIEW",
    "properties" : null
  }, {
    "time" : "2018-10-19T03:37:30.000+0000",
    "type" : "NAVIGATE",
    "properties" : null
  } ]
} ]

2020-03-16T11:54:40.130172+00:00 app[web.1]: 2020-03-16 11:54:40.129  INFO 4 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-16T11:54:40.198112+00:00 app[web.1]: 2020-03-16 11:54:40.197  WARN 4 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-16T11:54:40.485336+00:00 app[web.1]: 2020-03-16 11:54:40.484  INFO 4 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 35331 (http) with context path ''
2020-03-16T11:54:40.489500+00:00 app[web.1]: 2020-03-16 11:54:40.489  INFO 4 --- [           main] c.d.s.applogger.AppLoggerApplication     : Started AppLoggerApplication in 6.326 seconds (JVM running for 7.161)
2020-03-16T11:54:41.126105+00:00 heroku[web.1]: State changed from starting to up
2020-03-16T11:55:56.193750+00:00 app[web.1]: 2020-03-16 11:55:56.193  INFO 4 --- [io-35331-exec-4] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-16T11:55:56.193880+00:00 app[web.1]: 2020-03-16 11:55:56.193  INFO 4 --- [io-35331-exec-4] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-03-16T11:55:56.205768+00:00 app[web.1]: 2020-03-16 11:55:56.205  INFO 4 --- [io-35331-exec-4] o.s.web.servlet.DispatcherServlet        : Completed initialization in 12 ms
2020-03-16T11:55:56.575834+00:00 heroku[router]: at=info method=GET path="/" host=iredafe-mylogapp.herokuapp.com request_id=63782a64-1add-4bfe-b8c3-3160130033f7 fwd="129.205.113.98" dyno=web.1 connect=1ms service=413ms status=404 bytes=464 protocol=https
2020-03-16T11:57:16.839074+00:00 heroku[router]: at=info method=GET path="/" host=iredafe-mylogapp.herokuapp.com request_id=cb767ad2-867c-47ad-8953-85a024d14810 fwd="129.205.113.98" dyno=web.1 connect=1ms service=9ms status=404 bytes=464 protocol=https
2020-03-16T11:58:31.725548+00:00 heroku[router]: at=info method=GET path="/api/userlog" host=iredafe-mylogapp.herokuapp.com request_id=dd9d30b0-acdf-4bab-ad54-fc8f9c148171 fwd="129.205.113.98" dyno=web.1 connect=1ms service=12ms status=404 bytes=464 protocol=https
2020-03-16T11:58:39.978886+00:00 app[web.1]: 2020-03-16 11:58:39.978  INFO 4 --- [io-35331-exec-8] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2020-03-16T11:58:40.095567+00:00 app[web.1]: 2020-03-16 11:58:40.095  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@57256054 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.100280+00:00 app[web.1]: 2020-03-16 11:58:40.100  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@2e6603ed (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.103074+00:00 app[web.1]: 2020-03-16 11:58:40.102  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@523df1b5 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.105776+00:00 app[web.1]: 2020-03-16 11:58:40.105  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@41432ac9 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.108589+00:00 app[web.1]: 2020-03-16 11:58:40.108  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@34cfdd3d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.111372+00:00 app[web.1]: 2020-03-16 11:58:40.111  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@2a28d922 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.113734+00:00 app[web.1]: 2020-03-16 11:58:40.113  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@17a5358b (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.116145+00:00 app[web.1]: 2020-03-16 11:58:40.115  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@4fe840d4 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.118975+00:00 app[web.1]: 2020-03-16 11:58:40.118  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@5045a21 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.121925+00:00 app[web.1]: 2020-03-16 11:58:40.121  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@6989626a (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.232358+00:00 heroku[router]: at=info method=GET path="/api/userLog" host=iredafe-mylogapp.herokuapp.com request_id=79953046-9fcb-4947-be2c-9f74795ad507 fwd="129.205.113.98" dyno=web.1 connect=0ms service=292ms status=200 bytes=160 protocol=https
2020-03-16T11:58:54.348660+00:00 heroku[router]: at=info method=GET path="/api/userLog" host=iredafe-mylogapp.herokuapp.com request_id=10512910-6ce9-4e7b-aa67-3ffbd8431c99 fwd="129.205.113.98" dyno=web.1 connect=0ms service=14ms status=200 bytes=160 protocol=https
2020-03-16T11:58:54.634662+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=iredafe-mylogapp.herokuapp.com request_id=407b89b6-d3c5-4083-bcb4-2d7825f1254e fwd="129.205.113.98" dyno=web.1 connect=0ms service=19ms status=200 bytes=1136 protocol=https
2020-03-16T11:58:58.578822+00:00 heroku[router]: at=info method=GET path="/api/userLog" host=iredafe-mylogapp.herokuapp.com request_id=d54813e4-a705-4063-a8b2-f2c564e2621f fwd="129.205.113.98" dyno=web.1 connect=0ms service=13ms status=200 bytes=160 protocol=https

但是当我尝试使用heroku链接调用这个端点时,我只得到了这个空括号

[ ]

我不知道是什么问题。heroku错误日志如下所示:

[ {
  "userId" : "ABC123XYZ",
  "sessionId" : "XYZ456ABC",
  "action" : [ {
    "time" : "2018-10-19T03:37:28.000+0000",
    "type" : "CLICK",
    "properties" : {
      "locationX" : null,
      "locationY" : null,
      "viewedId" : null,
      "pageFrom" : null,
      "pageTo" : null
    }
  }, {
    "time" : "2018-10-19T03:37:28.000+0000",
    "type" : "CLICK",
    "properties" : {
      "locationX" : null,
      "locationY" : null,
      "viewedId" : null,
      "pageFrom" : null,
      "pageTo" : null
    }
  }, {
    "time" : "2018-10-19T03:37:28.000+0000",
    "type" : "CLICK",
    "properties" : {
      "locationX" : null,
      "locationY" : null,
      "viewedId" : null,
      "pageFrom" : null,
      "pageTo" : null
    }
  }, {
    "time" : "2018-10-19T03:37:30.000+0000",
    "type" : "VIEW",
    "properties" : null
  }, {
    "time" : "2018-10-19T03:37:30.000+0000",
    "type" : "NAVIGATE",
    "properties" : null
  } ]
} ]

2020-03-16T11:54:40.130172+00:00 app[web.1]: 2020-03-16 11:54:40.129  INFO 4 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-16T11:54:40.198112+00:00 app[web.1]: 2020-03-16 11:54:40.197  WARN 4 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-16T11:54:40.485336+00:00 app[web.1]: 2020-03-16 11:54:40.484  INFO 4 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 35331 (http) with context path ''
2020-03-16T11:54:40.489500+00:00 app[web.1]: 2020-03-16 11:54:40.489  INFO 4 --- [           main] c.d.s.applogger.AppLoggerApplication     : Started AppLoggerApplication in 6.326 seconds (JVM running for 7.161)
2020-03-16T11:54:41.126105+00:00 heroku[web.1]: State changed from starting to up
2020-03-16T11:55:56.193750+00:00 app[web.1]: 2020-03-16 11:55:56.193  INFO 4 --- [io-35331-exec-4] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-16T11:55:56.193880+00:00 app[web.1]: 2020-03-16 11:55:56.193  INFO 4 --- [io-35331-exec-4] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-03-16T11:55:56.205768+00:00 app[web.1]: 2020-03-16 11:55:56.205  INFO 4 --- [io-35331-exec-4] o.s.web.servlet.DispatcherServlet        : Completed initialization in 12 ms
2020-03-16T11:55:56.575834+00:00 heroku[router]: at=info method=GET path="/" host=iredafe-mylogapp.herokuapp.com request_id=63782a64-1add-4bfe-b8c3-3160130033f7 fwd="129.205.113.98" dyno=web.1 connect=1ms service=413ms status=404 bytes=464 protocol=https
2020-03-16T11:57:16.839074+00:00 heroku[router]: at=info method=GET path="/" host=iredafe-mylogapp.herokuapp.com request_id=cb767ad2-867c-47ad-8953-85a024d14810 fwd="129.205.113.98" dyno=web.1 connect=1ms service=9ms status=404 bytes=464 protocol=https
2020-03-16T11:58:31.725548+00:00 heroku[router]: at=info method=GET path="/api/userlog" host=iredafe-mylogapp.herokuapp.com request_id=dd9d30b0-acdf-4bab-ad54-fc8f9c148171 fwd="129.205.113.98" dyno=web.1 connect=1ms service=12ms status=404 bytes=464 protocol=https
2020-03-16T11:58:39.978886+00:00 app[web.1]: 2020-03-16 11:58:39.978  INFO 4 --- [io-35331-exec-8] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2020-03-16T11:58:40.095567+00:00 app[web.1]: 2020-03-16 11:58:40.095  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@57256054 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.100280+00:00 app[web.1]: 2020-03-16 11:58:40.100  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@2e6603ed (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.103074+00:00 app[web.1]: 2020-03-16 11:58:40.102  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@523df1b5 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.105776+00:00 app[web.1]: 2020-03-16 11:58:40.105  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@41432ac9 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.108589+00:00 app[web.1]: 2020-03-16 11:58:40.108  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@34cfdd3d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.111372+00:00 app[web.1]: 2020-03-16 11:58:40.111  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@2a28d922 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.113734+00:00 app[web.1]: 2020-03-16 11:58:40.113  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@17a5358b (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.116145+00:00 app[web.1]: 2020-03-16 11:58:40.115  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@4fe840d4 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.118975+00:00 app[web.1]: 2020-03-16 11:58:40.118  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@5045a21 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.121925+00:00 app[web.1]: 2020-03-16 11:58:40.121  WARN 4 --- [io-35331-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@6989626a (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-03-16T11:58:40.232358+00:00 heroku[router]: at=info method=GET path="/api/userLog" host=iredafe-mylogapp.herokuapp.com request_id=79953046-9fcb-4947-be2c-9f74795ad507 fwd="129.205.113.98" dyno=web.1 connect=0ms service=292ms status=200 bytes=160 protocol=https
2020-03-16T11:58:54.348660+00:00 heroku[router]: at=info method=GET path="/api/userLog" host=iredafe-mylogapp.herokuapp.com request_id=10512910-6ce9-4e7b-aa67-3ffbd8431c99 fwd="129.205.113.98" dyno=web.1 connect=0ms service=14ms status=200 bytes=160 protocol=https
2020-03-16T11:58:54.634662+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=iredafe-mylogapp.herokuapp.com request_id=407b89b6-d3c5-4083-bcb4-2d7825f1254e fwd="129.205.113.98" dyno=web.1 connect=0ms service=19ms status=200 bytes=1136 protocol=https
2020-03-16T11:58:58.578822+00:00 heroku[router]: at=info method=GET path="/api/userLog" host=iredafe-mylogapp.herokuapp.com request_id=d54813e4-a705-4063-a8b2-f2c564e2621f fwd="129.205.113.98" dyno=web.1 connect=0ms service=13ms status=200 bytes=160 protocol=https

更新

下面是用于从mysql获取日志的实体类,mysql生成了我前面显示的结果

首先是UserLog类

package com.dafe.spring.applogger.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name="log")
public class UserLog {

    //define field

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private int id;

    @Column(name="user_id")
    private String userId;

    @Column(name="session_id")
    private String sessionId;

    @OneToMany(mappedBy="userLog",cascade=CascadeType.ALL)
        private List<Action>action;
    //define constructors

    public UserLog() {

    }

    public UserLog(String userId, String sessionId) {
        this.userId = userId;
        this.sessionId = sessionId;
    }
    //define getters and setters


    public String getUserId() {
        return userId;
    }


    public void setUserId(String userId) {
        this.userId = userId;
    }


    public String getSessionId() {
        return sessionId;
    }


    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public List<Action> getAction() {
        return action;
    }


    public void setAction(List<Action> action) {
        this.action = action;
    }

    @Override
    public String toString() {
        return "Log [userId=" + userId + ", sessionId=" + sessionId + "]";
    }

}

这里是最后一个单属性实体类

package com.dafe.spring.applogger.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="properties")
public class Properties {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private int id;


    @Column(name="locationX")
    private Integer locationX;

    @Column(name="locationY")
    private Integer locationY;

    @Column(name="viewedId")
    private String viewedId;

    @Column(name="pageFrom")
    private String pageFrom;

    @Column(name="pageTo")
    private String pageTo;

    @JsonIgnore
    @OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="action_id")
    private Action action;


    public Properties() {

    }

    public Properties(Integer locationX, Integer locationY, String viewedId, String pageFrom, String pageTo) {
        this.locationX = locationX;
        this.locationY = locationY;
        this.viewedId = viewedId;
        this.pageFrom = pageFrom;
        this.pageTo = pageTo;
    }


    public Integer getLocationX() {
        return locationX;
    }

    public void setLocationX(Integer locationX) {
        this.locationX = locationX;
    }

    public Integer getLocationY() {
        return locationX;
    }

    public void setLocationY(Integer locationY) {
        this.locationY = locationY;
    }

    public String getViewedId() {
        return viewedId;
    }

    public void setViewedId(String viewedId) {
        this.viewedId = viewedId;
    }

    public String getPageFrom() {
        return pageFrom;
    }

    public void setPageFrom(String pageFrom) {
        this.pageFrom = pageFrom;
    }

    public String getPageTo() {
        return pageTo;
    }

    public void setPageTo(String pageTo) {
        this.pageTo = pageTo;
    }

    @Override
    public String toString() {
        return "Properties [locationX=" + locationX +", locationY=" + locationY + ", viewedId=" + viewedId + ", pageFrom=" + pageFrom + ", pageTo="
                + pageTo + "]";
    }

}
我如何使代码从heroku开始工作?我已经在heroku repo上为mysql配置了clearDB


如果有任何帮助或建议,我将不胜感激。谢谢

数据库中有您的数据吗?
尝试将mysql workbench与heroku为数据库连接提供的数据库URL连接。

在我看来,它无法创建到mysql数据库的连接。您需要提供更多关于这方面的源代码,以便找出问题所在