Boa noite Ao tentar iniciar o projeto, utilizando o vraptor 4 e seu plugin jpa. Ocorre o erro abaixo:
type Exception report
message br.com.caelum.vraptor.InterceptionException: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
description The server encountered an internal error that prevented it from fulfilling this request.
exception
br.com.caelum.vraptor.InterceptionException: br.com.caelum.vraptor.InterceptionException: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
br.com.caelum.vraptor.interceptor.StepInvoker.invokeMethod(StepInvoker.java:68)
br.com.caelum.vraptor.interceptor.StepInvoker.tryToInvoke(StepInvoker.java:54)
br.com.caelum.vraptor.interceptor.StepInvoker$Proxy$_$$_WeldClientProxy.tryToInvoke(Unknown Source)
br.com.caelum.vraptor.interceptor.InterceptorExecutor.executeAround(InterceptorExecutor.java:75)
br.com.caelum.vraptor.interceptor.InterceptorExecutor$Proxy$_$$_WeldClientProxy.executeAround(Unknown Source)
br.com.caelum.vraptor.interceptor.AspectStyleInterceptorHandler.execute(AspectStyleInterceptorHandler.java:87)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:83)
br.com.caelum.vraptor.core.DefaultInterceptorStack.start(DefaultInterceptorStack.java:93)
br.com.caelum.vraptor.core.DefaultInterceptorStack$Proxy$_$$_WeldClientProxy.start(Unknown Source)
br.com.caelum.vraptor.observer.RequestHandlerObserver.handle(RequestHandlerObserver.java:86)
sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:266)
org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:253)
org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:232)
org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:169)
org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:165)
org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:119)
org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:112)
org.jboss.weld.event.EventImpl.fire(EventImpl.java:83)
br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:116)
Ele não está localizando o persistenceUnit default, embora ele encontra-se em src/main/resources/META-INF/persistence.xml.
Arquivo persistence.
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="default">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/vraptorprodutos"/>
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
Segue também meu ProdutoDAO e o ProdutoController
package br.com.estudo.controller;
import javax.inject.Inject;
import javax.validation.Valid;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Result;
import br.com.estudo.dao.ProdutoDao;
import br.com.estudo.model.Produto;
@Controller
public class ProdutoController {
private final ProdutoDao dao;
private final Result result;
@Inject
public ProdutoController(ProdutoDao dao, Result result) {
this.dao = dao;
this.result = result;
}
@Deprecated
public ProdutoController() {
this(null, null);
}
@Get("/")
public void inicio(){
}
@Get
public void formulario(){
}
public void adiciona(@Valid Produto produto){
dao.adiciona(produto);
result.include("mensagem", "Produto adiciona com sucesso");
result.redirectTo(this).formulario();
}
}
package br.com.estudo.dao;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import br.com.estudo.model.Produto;
@RequestScoped
public class ProdutoDao {
private final EntityManager em;
@Inject
public ProdutoDao(EntityManager em) {
this.em = em;
}
@Deprecated
public ProdutoDao() {
this(null);
}
public void adiciona(Produto produto){
em.persist(produto);
}
}
E o web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>estudo-vraptor</display-name>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<context-param>
<param-name>br.com.caelum.vraptor.environment</param-name>
<param-value>production</param-value>
</context-param>
</web-app>