Проблемы с развернутым приложением Springboot на Heroku - PullRequest
0 голосов
/ 16 марта 2020

Я развернул SpringAb RestApi на Heroku. Когда я запускаю этот проект на моем компьютере через http://localhost: 8080 / api / userLog , я получаю желаемый ответ, который показан ниже:

[ {
  "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
  } ]
} ]

, но когда я пытаюсь вызвать это конечная точка с помощью ссылки героку https://iredafe-mylogapp.herokuapp.com/api/userLog, я получаю только эти пустые скобки.

[ ]

Я не знаю, в чем проблема. Журналы ошибок heroku можно увидеть ниже:

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

UPDATE

Вот классы сущностей, которые использовались для получения журналов из 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 java.sql.Timestamp;
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.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;


@Entity
@Table(name="action")
public class Action {

    //declare & annotate your fields
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
    private int id;

@Column(name="time")
    private Timestamp time;

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

@JsonIgnore
@ManyToOne
@JoinColumn(name="log_id")
private UserLog userLog;


@OneToOne(mappedBy="action", cascade=CascadeType.ALL)
private Properties properties;


    //create and generate constructor
    public Action() {

    }

    public Action(Timestamp time, String type) {
        this.time = time;
        this.type = type;
    }

    //generate getters and setters

    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    @Override
    public String toString() {
        return "Action [\n time=" + time + ",\n type=" + type  + "]";
    }

    //generate toString 



}

Вот последняя - Свойства сущности класса

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? Я уже подготовил clearDB для mysql на репозитории heroku.

Буду признателен за любую помощь или предложения. Спасибо

...