简体   繁体   English

使用Springboot和Elide时EntityManagerFactory为null

[英]EntityManagerFactory is null using Springboot and Elide

I am trying to get a JSON API-compliant RESTful service working with Spring Boot and Elide by following this tutorial: https://dzone.com/articles/create-a-json-api-rest-service-with-spring-boot-an and this example code: https://github.com/mcasperson/spring-boot-jpa-elide/ 我通过遵循此教程来尝试使用Spring Boot和Elide获得与JSON API兼容的RESTful服务: https : //dzone.com/articles/create-a-json-api-rest-service-with-spring-boot -an和此示例代码: https : //github.com/mcasperson/spring-boot-jpa-elide/

But EntityManagerFactory is null at this line: https://github.com/mcasperson/spring-boot-jpa-elide/blob/master/src/main/java/com/matthewcasperson/elidetest/ElideTest.java#L60 但是EntityManagerFactory在此行为空: https : //github.com/mcasperson/spring-boot-jpa-elide/blob/master/src/main/java/com/matthewcasperson/elidetest/ElideTest.java#L60

I'm not sure how to trouble shoot the @Autowired annotation: https://github.com/mcasperson/spring-boot-jpa-elide/blob/master/src/main/java/com/matthewcasperson/elidetest/ElideTest.java#L31-L32 to figure out why the EntityManagerFactory is null . 我不确定如何麻烦拍摄@Autowired注释: https : //github.com/mcasperson/spring-boot-jpa-elide/blob/master/src/main/java/com/matthewcasperson/elidetest/ElideTest。 java#L31-L32找出EntityManagerFactory为什么为null

Any ideas what sort of things I can try to troubleshoot this? 有什么主意我可以尝试解决的问题吗? I'm new to the Java world so I'm a bit lost. 我是Java世界的新手,所以我有点迷路。

My app didn't have a database but I added a H2 database just in case it mattered for the EntityManagerFactory. 我的应用程序没有数据库,但是我添加了一个H2数据库,以防它对EntityManagerFactory至关重要。

Thank you for your time. 感谢您的时间。 :) :)

It turned out that the method using the EntityManagerFactory needs to have a particular signature in order for the @Autowired annotation to work. 事实证明,使用EntityManagerFactory的方法需要具有特定的签名,才能使@Autowired批注起作用。

So this line affect the @Autowired annotation: https://github.com/mcasperson/spring-boot-jpa-elide/blob/master/src/main/java/com/matthewcasperson/elidetest/ElideTest.java#L49 所以这一行会影响@Autowired注释: https : //github.com/mcasperson/spring-boot-jpa-elide/blob/master/src/main/java/com/matthewcasperson/elidetest/ElideTest.java#L49

Hope that helps other Java newbies like me :) 希望对其他像我这样的Java新手有所帮助:)

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

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