Search code examples
javaspring-bootjson-api

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/

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

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.

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.

My app didn't have a database but I added a H2 database just in case it mattered for the EntityManagerFactory.

Thank you for your time. :)


Solution

  • It turned out that the method using the EntityManagerFactory needs to have a particular signature in order for the @Autowired annotation to work.

    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

    Hope that helps other Java newbies like me :)