简体   繁体   English

Spring Boot + Postgres + JPA + Heroku无法持久存储数据并且无法记录日志

[英]Spring boot + Postgres + JPA + Heroku not persisting data and not logging

I have a very simple Spring Boot application deployed on Heroku. 我在Heroku上部署了一个非常简单的Spring Boot应用程序。 The application itself works fine in terms of the Controller - the API returns some simple JSON, nothing too special. 应用程序本身就控制器而言运行良好-API返回一些简单的JSON,没有什么特别的。

I've added a Postgres database to Heroku and on application startup I see that Spring creates the table as expected. 我已将Postgres数据库添加到Heroku,并且在应用程序启动时,我看到Spring按预期方式创建了该表。 It is only 1 table with a super simple mapping class: 它只有1个具有超简单映射类的表:

@Entity
public class Score implements Serializable {
private static final long serialVersionUID = -2899157432342241888L;

private String customer;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

private Date date = new Date();

private int score;

//setters and getters

The repository is just an interface with no explicit implementation: 存储库只是一个接口,没有明确的实现:

@Repository
public interface ScoreRepository extends CrudRepository<Score, Long>

I call repository.save(...) in a @Service annotated class that has the repository auto-wired in. I assume that is working ok, because I'm not seeing any errors - yet I don't see any records being persisted to the database! 我在自动插入资源库的@Service注释的类中调用了repository.save(...) 。我认为这是可以的,因为我没有看到任何错误-但是我没有看到任何记录坚持到数据库! No idea what could be going wrong here; 不知道这里可能出什么问题; I suppose I could have set up Heroku wrong, or maybe there's something obvious that I missed with the Postgres setup in Heroku? 我想我可能错误地设置了Heroku,或者可能我在Heroku中的Postgres设置中错过了一些明显的东西?

Secondary question 次要问题

Maybe related, but logging doesn't seem to work too well either. 也许相关,但是日志记录似乎也不是很好。 According to Heroku documentation I can print to standard out and it should appear in the log, but this doesn't happen. 根据Heroku文档,我可以打印到标准输出,它应该出现在日志中,但是不会发生。 Moreover I have this in properties file: 而且我在属性文件中有这个:

spring.jpa.show-sql=true

But I see no such logging of SQL queries in the heroku logs. 但是我在heroku日志中没有看到这样的SQL查询日志。

Any help much appreciated! 任何帮助,不胜感激! Thanks in advance. 提前致谢。

Logging issue: when you start your application, do you see any errors in console (first few lines even before spring logo) saying multiple version of logging jar (slf4j.jar) , if so you may not see logs. 日志记录问题:启动应用程序时,您是否在控制台中看到任何错误(甚至在spring徽标之前还有前几行),指出日志记录罐(slf4j.jar)的多个版本,如果这样,您可能看不到日志。 If this is true, then check your maven depencies and exclude all unncessary slf4j.jar 如果这是真的,那么请检查您的Maven依赖关系并排除所有不必要的slf4j.jar

and start your spring application with debug. 并通过调试启动spring应用程序。

java -jar myapp.jar --debug

persistence issue: Make sure you run it in transaction (in spring context) 持久性问题:确保在事务中运行它(在春季上下文中)

After you solve your logging issue you can figure this out i believe, But you can debug your code and see if request reaches your save method, and then you can step into to find if there is any issue, But i would definitely see logs to find errors if any. 解决您的日志记录问题后,您可以确定这一点,但是,您可以调试代码,查看请求是否达到保存方法,然后您可以介入以查找是否存在任何问题,但是我肯定会看到日志查找错误(如果有)。

I don't see a setter. 我没有看到二传手。 Do you even have it as all I see is comment // Getter and setter 您是否拥有它,因为我只看到注释//吸气剂和吸气剂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM