Olá pessoal!
Estou tendo um erro ao tentar consultar os pedidos na base de dados, o erro diz que o entityMananger está vindo nulo, o que poderia ser?
Controller
package br.com.alura.mvc.mudi.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import br.com.alura.mvc.mudi.model.Pedido;
public class PedidosDAO {
@PersistenceContext
private EntityManager entityMananger;
public List<Pedido> consultaTodosPedidos(){
Query query = entityMananger.createNamedQuery("SELECT * FROM pedido", Pedido.class);
List<Pedido> pedidos = query.getResultList();
return pedidos;
}
}
POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Erro
ERROR 22132 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException: Cannot invoke "javax.persistence.EntityManager.createNamedQuery(String, java.lang.Class)" because "this.entityMananger" is null] with root cause
java.lang.NullPointerException: Cannot invoke "javax.persistence.EntityManager.createNamedQuery(String, java.lang.Class)" because "this.entityMananger" is null
Valeu pela força!