Pessoal estou tentando estabelecer a injeção de dependência instanciando o EntityManager do JPA no VRaptor e estou obtendo este erro abaixo:
Como poderão ver o datasource está sendo invocado e gerando o pool de conexão com o JBoss: Bound data source [java:jboss/MajorEnterpriseJourneyDS]
Porém ocorre um erro ao invocar o datasource via JNDI na classe CriarSessao
this.entityManagerFactory = Persistence.createEntityManagerFactory(“MajorEnterpriseJourney”);
a informação sugerida no log do JBoss é que já existe uma conexão configurada e por tanto ativa.
Ao remover esta linha gera outro erro informando que não consegue executar o método create justamente por não ter sido feito o lookup JNDI, neste caso entendo como a conexão disponível mas não carregada para o contexto JPA da aplicação.
Qualquer ajuda será válida.
Segue as principais configurações do ambiente em questão:
VRaptor 3.5.3
maven-3.0.4
Sql Server 2012
JPA 2.1
JBoss EAP 6.1.0.Alpha1 (AS 7.2.0.Alpha1-redhat-4)
SO Windows 7
java 1.7.0_06
Log
[code]15:24:25,470 INFO [org.jboss.as.server.deployment] (MSC service thread 1-10) JBAS015876: Starting deployment of “MajorEnterpriseJourney.war” (runtime-name: “MajorEnterpriseJourney.war”)
15:24:25,586 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-10) JBAS010400: Bound data source [java:jboss/MajorEnterpriseJourneyDS]
15:24:26,629 WARN [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name ‘org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer’ for service type 'org.xmlpull.v1.XmlPullParserFactory’
15:24:27,692 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-10) JBAS010403: Deploying JDBC-compliant driver class org.hsqldb.jdbc.JDBCDriver (version 2.2)
15:24:27,695 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-10) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
15:24:27,696 WARN [org.jboss.weld.deployer] (MSC service thread 1-10) JBAS016012: Deployment deployment “MajorEnterpriseJourney.war” contains CDI annotations but beans.xml was not found.
15:24:27,749 INFO [org.jboss.web] (ServerService Thread Pool – 68) JBAS018210: Register web context: /MajorEnterpriseJourney
15:24:28,787 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MajorEnterpriseJourney]] (ServerService Thread Pool – 68) JBWEB000284: Exception starting filter vraptor: com.google.inject.CreationException: Guice creation errors:
- A binding to br.com.caelum.vraptor.ioc.ComponentFactory<javax.persistence.EntityManager> was already configured at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.registerFactory(GuiceComponentRegistry.java:171).
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.registerFactory(GuiceComponentRegistry.java:171)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:95) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:83) [guice-3.0.jar:]
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97) [vraptor-3.5.3.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119) [vraptor-3.5.3.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113) [vraptor-3.5.3.jar:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_06]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_06]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
15:24:28,790 ERROR [org.apache.catalina.core] (ServerService Thread Pool – 68) JBWEB001103: Error detected during context /MajorEnterpriseJourney start, will stop it
15:24:28,806 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool – 68) MSC00001: Failed to start service jboss.web.deployment.default-host./MajorEnterpriseJourney: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./MajorEnterpriseJourney: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_06]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_06]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:161)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
… 7 more
[/code]
standalone.xml
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
<datasources>
<datasource jndi-name="java:jboss/MajorEnterpriseJourneyDS" pool-name="MajorEnterpriseJourneyDS">
<connection-url>jdbc:sqlserver://localhost:1433;databaseName=MajorEnterpriseJourneyDB</connection-url>
<driver>sqlserver</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>****</user-name>
<password>****</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
</validation>
</datasource>
<drivers>
<driver name="sqlserver" module="com.microsoft">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
Persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="MajorEnterpriseJourney">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/MajorEnterpriseJourneyDS</jta-data-source>
<class>mej.model.Cidade</class>
<class>mej.model.Acomodacao</class>
<class>mej.model.Aeroporto</class>
<class>mej.model.AeroportoDestino</class>
<class>mej.model.AeroportoOrigem</class>
<class>mej.model.Cliente</class>
<class>mej.model.CoberturaSeguradora</class>
<class>mej.model.CompanhiaAerea</class>
<class>mej.model.CompanhiaMaritima</class>
<class>mej.model.Cotacao</class>
<class>mej.model.CruzeiroMaritimo</class>
<class>mej.model.Destino</class>
<class>mej.model.Estado</class>
<class>mej.model.Estorno</class>
<class>mej.model.Evento</class>
<class>mej.model.Funcionario</class>
<class>mej.model.Hospedagem</class>
<class>mej.model.ItemGrafico</class>
<class>mej.model.ItemPreco</class>
<class>mej.model.MaterialGrafico</class>
<class>mej.model.MaterialGraficoItem</class>
<class>mej.model.MovimentacaoFinanceira</class>
<class>mej.model.Origem</class>
<class>mej.model.PacoteTuristico</class>
<class>mej.model.PacoteTuristicoEvento</class>
<class>mej.model.PassagemAerea</class>
<class>mej.model.Reserva</class>
<class>mej.model.Seguradora</class>
<class>mej.model.Usuario</class>
</persistence-unit>
</persistence>
Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.MajorEnterpriseJourney</groupId>
<artifactId>MajorEnterpriseJourney</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Sistema MajorEnterpriseJourney Web-App</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>br.com.caelum.vraptor</groupId>
<artifactId>vraptor-jpa</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.24</version>
</dependency>
<dependency>
<groupId>br.com.caelum</groupId>
<artifactId>vraptor</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<!-- Facebook dependencie -->
<dependency>
<groupId>org.facebook4j</groupId>
<artifactId>facebook4j-core</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.3.3</version>
</dependency>
<!-- Provided dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<build>
<finalName>MajorEnterpriseJourney</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.14</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
</reporting>
</project>
CriaSessao
package br.com.majorEnterpriseJourney.infra;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.ComponentFactory;
@Component
public class CriaSessao implements ComponentFactory<EntityManager> {
private EntityManager entityManager;
private final EntityManagerFactory entityManagerFactory;
public CriaSessao(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = Persistence.createEntityManagerFactory("MajorEnterpriseJourney");
}
@PostConstruct
public void abre() {
this.entityManager = this.entityManagerFactory.createEntityManager();
}
public EntityManager getInstance() {
return this.entityManager;
}
@PreDestroy
public void fecha() {
this.entityManager.close();
}
}
ClienteController
package br.com.majorEnterpriseJourney.controller;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;
import br.com.caelum.vraptor.Delete;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Put;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.Validator;
import br.com.majorEnterpriseJourney.model.Cliente;
import br.com.majorEnterpriseJourney.service.ClienteService;
import br.com.majorEnterpriseJourney.util.ConstantesUtil;
@Resource
public class ClienteController implements ControllerIF<Cliente> {
@SuppressWarnings("unused")
private static final Logger LOG = Logger.getLogger(ClienteController.class);
private final Result result;
private final Validator validator;
private final ClienteService clienteService;
private static ResourceBundle bundle;
public ClienteController(ClienteService clienteService, Result result, Validator validator) {
this.result = result;
this.validator = validator;
this.clienteService = clienteService;
bundle = ResourceBundle.getBundle(ConstantesUtil.MESSAGES_RESOURCE);
}
@Override
@Get("/clientes")
public void index() {
}
@Override
@Post("/clientes")
public void create(Cliente cliente) {
validator.validate(cliente);
validator.onErrorUsePageOf(this).novo();
clienteService.create(cliente);
result.include("notice", bundle.getString("registro.incluido")).redirectTo(this).index();
}
@Override
@Get("/clientes/novo")
public void novo() {
result.include("cliente", new Cliente());
}
@Override
@Put("/clientes")
public void update(Cliente cliente) {
validator.validate(cliente);
validator.onErrorUsePageOf(this).edit(cliente);
clienteService.update(cliente);
result.include("notice", bundle.getString("registro.atualizado")).redirectTo(this).index();
}
@Override
@Get("/clientes/{cliente.id}/edit")
public void edit(Cliente cliente) {
result.include("cliente", clienteService.findById(cliente.getId()));
}
@Override
@Delete("/clientes/{cliente.id}")
public void delete(Cliente cliente) {
clienteService.delete(clienteService.findById(cliente.getId()));
result.include("notice", bundle.getString("registro.excluido")).redirectTo(this).index();
}
}
ClienteService
package br.com.majorEnterpriseJourney.service;
import java.util.Collection;
import java.util.List;
import br.com.caelum.vraptor.ioc.Component;
import br.com.majorEnterpriseJourney.dao.ClienteDAO;
import br.com.majorEnterpriseJourney.model.Cliente;
@Component
public class ClienteService implements ServiceIF<Cliente> {
private final ClienteDAO clienteDAO;
public ClienteService(ClienteDAO clienteDAO) {
this.clienteDAO = clienteDAO;
}
@Override
public void create(Cliente entity) {
clienteDAO.create(entity);
}
@Override
public Cliente update(Cliente entity) {
return clienteDAO.update(entity);
}
@Override
public void delete(Cliente entity) {
clienteDAO.delete(entity);
}
@Override
public Collection<Cliente> findAll() {
return (List<Cliente>) clienteDAO.findAll();
}
@Override
public Cliente findById(Long id) {
return clienteDAO.findById(id);
}
}
CienteDAO
package br.com.majorEnterpriseJourney.dao;
import javax.persistence.EntityManager;
import br.com.caelum.vraptor.ioc.Component;
import br.com.majorEnterpriseJourney.model.Cliente;
@Component
public class ClienteDAO extends GenericDAO<Cliente> {
public ClienteDAO(EntityManager entityManager) {
super(entityManager);
}
}
GenericDAO
package br.com.majorEnterpriseJourney.dao;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import br.com.majorEnterpriseJourney.model.GenericModel;
public abstract class GenericDAO<T extends GenericModel> {
public final EntityManager entityManager;
protected final Class<T> clazz;
private ResourceBundle bundle;
@SuppressWarnings("unchecked")
public GenericDAO(EntityManager entityManager) {
this.entityManager = entityManager;
this.bundle = ResourceBundle.getBundle("configs");
this.clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
public void create(T entity) {
entityManager.getTransaction().begin();
entityManager.persist(entity);
entityManager.getTransaction().commit();
}
@SuppressWarnings("unchecked")
public T update(T entity) {
entityManager.getTransaction().begin();
T object = (T) entityManager.merge(entity);
entityManager.getTransaction().commit();
return object;
}
public void delete(T entity) {
entityManager.getTransaction().begin();
entityManager.remove(entity);
entityManager.getTransaction().commit();
}
@SuppressWarnings("unchecked")
public Collection<T> findAll() {
return entityManager.createQuery("select o from ", clazz).getResultList();
}
@SuppressWarnings("unchecked")
public T findById(Long id) {
return (T) entityManager.find(this.clazz, id);
}
@SuppressWarnings("unchecked")
public T ultimoRegistro(String campoID) {
String sql = "select MAX(id) from " + this.clazz.getName();
Query query = entityManager.createQuery(sql);
return (T) findById((Long) query.getSingleResult());
}
public void refresh(T entity) {
entityManager.refresh(entity);
}
/**
* Retorna nulo caso não seja passado nenhum parametro.
* @param query
* @param params
* @return
*/
@SuppressWarnings("unchecked")
public T getWithParams(String query, Object... params) {
return params.length == 0 ? null : (T) preparaParametros(query, params).getSingleResult();
}
@SuppressWarnings("unchecked")
public List<T> getListWithParams(String query, Object... params) {
return preparaParametros(query, params).getResultList();
}
/**
* Prapara a query e sua lista de parametros.
* @param query
* @param params
* @return Query
*/
private Query preparaParametros(String query, Object... params) {
Query qr = entityManager.createQuery(query);
if (params != null) {
for (int i = 0; i < params.length; i++) {
qr.setParameter(i, params[i]);
}
}
return qr;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>emprestimos</display-name>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<!-- <param-value>br.com.empresa.pacote.messages</param-value> -->
<param-value>messages</param-value>
</context-param>
<!-- FAZ COM QUE O VRAPTOR CONTROLE AS TRANSACOES -->
<!-- <context-param>
<param-name>br.com.caelum.vraptor.provider</param-name>
<param-value>br.com.caelum.vraptor.util.hibernate.HibernateCustomProvider</param-value>
</context-param> -->
<context-param>
<param-name>br.com.caelum.vraptor.encoding</param-name>
<param-value>UTF-8</param-value>
</context-param>
<filter>
<filter-name>vraptor</filter-name>
<filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
<filter-mapping>
<filter-name>vraptor</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
<include-prelude>/WEB-INF/jsp/prelude.jspf</include-prelude>
</jsp-property-group>
</jsp-config>
</web-app>
remova esse cara do seu pom.xml:
<dependency>
<groupId>br.com.caelum.vraptor</groupId>
<artifactId>vraptor-jpa</artifactId>
<version>1.0.0</version>
</dependency>
ou remova os seus componentFactory<EntityManager(Factory)> e renomeie a persistence-unit no persistence.xml pra default
Lucas,
removi a classe CriaSessao, mantive a dependencia vraptor-jpa e alterei o nome da persistence-unit para default conforme orientações, agora passei a obter essas 2 issue:
21:43:13,066 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-14) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
21:43:13,067 WARN [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016012: Deployment deployment “MajorEnterpriseJourney.war” contains CDI annotations but beans.xml was not found.
21:43:14,186 INFO [org.jboss.web] (ServerService Thread Pool – 68) JBAS018210: Register web context: /MajorEnterpriseJourney
21:43:17,995 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MajorEnterpriseJourney]] (ServerService Thread Pool – 68) JBWEB000284: Exception starting filter vraptor: com.google.inject.CreationException: Guice creation errors:
- Error notifying InjectionListener br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor@672f8297 of br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator.
Reason: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.bindToConstructor(GuiceComponentRegistry.java:151)
while locating br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator
Caused by: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:45)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withoutArgs(MethodHandlerByMethod.java:58)
at br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor.afterInjection(ScopeLifecycleListener.java:89)
at com.google.inject.internal.MembersInjectorImpl.notifyListeners(MembersInjectorImpl.java:97)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:95)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:65)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:204)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:198)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:198)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:179)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:83)
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791)
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator.getEntityManagerFactory(EntityManagerFactoryCreator.java:54)
at br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator.create(EntityManagerFactoryCreator.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
… 35 more
- Error notifying InjectionListener br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor@672f8297 of br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator.
Reason: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.bindToConstructor(GuiceComponentRegistry.java:151)
while locating br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator
while locating br.com.caelum.vraptor.ioc.ComponentFactory<javax.persistence.EntityManagerFactory>
Caused by: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:45)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withoutArgs(MethodHandlerByMethod.java:58)
at br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor.afterInjection(ScopeLifecycleListener.java:89)
at com.google.inject.internal.MembersInjectorImpl.notifyListeners(MembersInjectorImpl.java:97)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:95)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:65)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:54)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:204)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:198)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:198)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:179)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:83)
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791)
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator.getEntityManagerFactory(EntityManagerFactoryCreator.java:54)
at br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator.create(EntityManagerFactoryCreator.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
… 36 more
2 errors
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:183) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:95) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:83) [guice-3.0.jar:]
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97) [vraptor-3.5.3.jar:]
Quando eu removi a dependencia vraptor-jpa, retornei a persistence-unit name=“MajorEnterpriseJourney” e passei a usar novamente classe CriaSessao obtive esta outra issue:
22:02:54,364 INFO [org.jboss.as.remoting] (MSC service thread 1-8) JBAS017100: Listening on 127.0.0.1:9999
22:02:54,364 INFO [org.jboss.as.remoting] (MSC service thread 1-10) JBAS017100: Listening on 127.0.0.1:4447
22:02:54,366 INFO [org.jboss.as.server.deployment] (MSC service thread 1-14) JBAS015876: Starting deployment of “MajorEnterpriseJourney.war” (runtime-name: “MajorEnterpriseJourney.war”)
22:02:54,473 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-15) JBAS010400: Bound data source [java:jboss/MajorEnterpriseJourneyDS]
22:02:55,654 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015893: Encountered invalid class name ‘org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer’ for service type 'org.xmlpull.v1.XmlPullParserFactory’
22:02:56,155 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-15) JBAS010403: Deploying JDBC-compliant driver class org.hsqldb.jdbc.JDBCDriver (version 2.2)
22:02:56,159 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-15) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
22:02:56,160 WARN [org.jboss.weld.deployer] (MSC service thread 1-15) JBAS016012: Deployment deployment “MajorEnterpriseJourney.war” contains CDI annotations but beans.xml was not found.
22:02:56,202 INFO [org.jboss.web] (ServerService Thread Pool – 64) JBAS018210: Register web context: /MajorEnterpriseJourney
22:02:57,024 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MajorEnterpriseJourney]] (ServerService Thread Pool – 64) JBWEB000284: Exception starting filter vraptor: com.google.inject.CreationException: Guice creation errors:
- No implementation for javax.persistence.EntityManagerFactory was bound.
while locating javax.persistence.EntityManagerFactory
for parameter 0 at br.com.majorEnterpriseJourney.infra.CriaSessao.(CriaSessao.java:18)
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.bindToConstructor(GuiceComponentRegistry.java:151)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:95) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:83) [guice-3.0.jar:]
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97) [vraptor-3.5.3.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119) [vraptor-3.5.3.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113) [vraptor-3.5.3.jar:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_06]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_06]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
22:02:57,030 ERROR [org.apache.catalina.core] (ServerService Thread Pool – 64) JBWEB001103: Error detected during context /MajorEnterpriseJourney start, will stop it
22:02:57,046 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool – 64) MSC00001: Failed to start service jboss.web.deployment.default-host./MajorEnterpriseJourney: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./MajorEnterpriseJourney: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_06]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_06]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:161)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
Cheguei a ver este tópico também http://www.guj.com.br/java/301394-vraptor---erro-no-construtor-do-business---javaxpersistenceentitymanager--erro#1601002
mas estou usando esta dependencia do vraptor:
br.com.caelum
vraptor
3.5.3
Não acredito que seja um problema de versão do jar.
Lucas, removi a classe CriaSessao do projeto e fiz a configuração correta conforme sugestão sua em outros tópicos usando
EntityManagerCreator e EntityManagerFactoryCreator além disso removi a dependencia vraptor-jpa conforme solicitado
EntityManagerCreator
package br.com.majorEnterpriseJourney.infra;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.ComponentFactory;
import br.com.caelum.vraptor.ioc.RequestScoped;
@Component
@RequestScoped
public class EntityManagerCreator implements ComponentFactory<EntityManager>{
private final EntityManagerFactory factory;
private EntityManager entityManager;
public EntityManagerCreator(EntityManagerFactory factory) {
this.factory = factory;
}
@PostConstruct
public void create() {
entityManager = factory.createEntityManager();
}
public EntityManager getInstance() {
return entityManager;
}
@PreDestroy
public void destroy() {
entityManager.close();
}
}
EntityManagerFactoryCreator
package br.com.majorEnterpriseJourney.infra;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.ComponentFactory;
@Component
@ApplicationScoped
public class EntityManagerFactoryCreator implements ComponentFactory<EntityManagerFactory>{
private EntityManagerFactory factory;
@PostConstruct
public void create() {
factory = getEntityManagerFactory();
}
public EntityManagerFactory getInstance() {
return factory;
}
@PreDestroy
public void destroy() {
factory.close();
}
protected EntityManagerFactory getEntityManagerFactory() {
return Persistence.createEntityManagerFactory("default");
}
}
Está dando esses erros agora, tah osso:
- Error notifying InjectionListener br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor@487220c0 of br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.
Reason: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.bindToConstructor(GuiceComponentRegistry.java:151)
while locating br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator
Caused by: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:45)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withoutArgs(MethodHandlerByMethod.java:58)
at br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor.afterInjection(ScopeLifecycleListener.java:89)
at com.google.inject.internal.MembersInjectorImpl.notifyListeners(MembersInjectorImpl.java:97)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:95)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:65)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:204)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:198)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:198)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:179)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:83)
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791)
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.getEntityManagerFactory(EntityManagerFactoryCreator.java:37)
at br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.create(EntityManagerFactoryCreator.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
- Error notifying InjectionListener br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor@487220c0 of br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.
Reason: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.bindToConstructor(GuiceComponentRegistry.java:151)
while locating br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator
while locating br.com.caelum.vraptor.ioc.ComponentFactory
Caused by: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:45)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withoutArgs(MethodHandlerByMethod.java:58)
at br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor.afterInjection(ScopeLifecycleListener.java:89)
at com.google.inject.internal.MembersInjectorImpl.notifyListeners(MembersInjectorImpl.java:97)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:95)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:65)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:54)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:204)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:198)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:198)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:179)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:83)
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791)
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.getEntityManagerFactory(EntityManagerFactoryCreator.java:37)
at br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.create(EntityManagerFactoryCreator.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
… 36 more
3 errors
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:183) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:95) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:83) [guice-3.0.jar:]
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97) [vraptor-3.5.3.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119) [vraptor-3.5.3.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113) [vraptor-3.5.3.jar:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791) [jbossweb-7.2.0.Final.jar:7.2.0.Final]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [rt.jar:1.7.0_06]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_06]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_06]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
verifica se o seu persistence.xml está em :classpath:/META-INF/persistence.xml
e verifica se o persistence-unit se chama default.
Lucas,
Precisei alterar a estrutura do projeto modificando localização da pasta META-INF para src/main/resources/META-INF e colocar o persistence.xml nesta pasta.
Antes o persistence.xml estava localizado na pasta META-INF dentro do target e por isso nunca encontrava o persistense.xml e assim não era possível instanciar o create do EntityManager.
Valeu mesmo pela ajuda.
Pessoal, embora tenha resolvido uma série de erros anteriormente ainda não consegui instanciar o EntityManager do JPA no VRaptor, alguma coisa está errada e não estou entendendo o erro
Descobri depois de alguns erros gerados no log que o JBoss EAP 6.1 não empacota o provedor JPA EclipseLink no WAR durante o processo de deploy, sendo necessário configurar um modulo específico apontando para o jar do plugin
Segui este tutorial orientado pela própria comunidade do app server e resolvi os erros https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7
Precisei criar o seguinte arquivo module.xml no caminho …\jboss-eap-6.1\modules\system\layers\base\org\eclipse\persistence\main
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence">
<resources>
<resource-root path="eclipselink-2.5.0.jar"/>
</resources>
<dependencies>
<module name="asm.asm"/>
<module name="javax.api"/>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="javax.validation.api"/>
<module name="javax.xml.bind.api"/>
<module name="org.antlr"/>
<module name="org.apache.commons.collections"/>
<module name="org.dom4j"/>
<module name="org.javassist"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>
Após algumas alterações o arquivo persistence.xml encontra-se desta forma
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="default" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/MajorEnterpriseJourneyDS</jta-data-source>
<class>br.com.majorEnterpriseJourney.model.GenericModel</class>
<class>br.com.majorEnterpriseJourney.model.Cidade</class>
<class>br.com.majorEnterpriseJourney.model.Acomodacao</class>
<class>br.com.majorEnterpriseJourney.model.Aeroporto</class>
<class>br.com.majorEnterpriseJourney.model.AeroportoDestino</class>
<class>br.com.majorEnterpriseJourney.model.AeroportoOrigem</class>
<class>br.com.majorEnterpriseJourney.model.Cliente</class>
<class>br.com.majorEnterpriseJourney.model.CoberturaSeguradora</class>
<class>br.com.majorEnterpriseJourney.model.CompanhiaAerea</class>
<class>br.com.majorEnterpriseJourney.model.CompanhiaMaritima</class>
<class>br.com.majorEnterpriseJourney.model.Cotacao</class>
<class>br.com.majorEnterpriseJourney.model.CruzeiroMaritimo</class>
<class>br.com.majorEnterpriseJourney.model.Destino</class>
<class>br.com.majorEnterpriseJourney.model.Estado</class>
<class>br.com.majorEnterpriseJourney.model.Estorno</class>
<class>br.com.majorEnterpriseJourney.model.Evento</class>
<class>br.com.majorEnterpriseJourney.model.Funcionario</class>
<class>br.com.majorEnterpriseJourney.model.Hospedagem</class>
<class>br.com.majorEnterpriseJourney.model.ItemGrafico</class>
<class>br.com.majorEnterpriseJourney.model.ItemPreco</class>
<class>br.com.majorEnterpriseJourney.model.MaterialGrafico</class>
<class>br.com.majorEnterpriseJourney.model.MaterialGraficoItem</class>
<class>br.com.majorEnterpriseJourney.model.MovimentacaoFinanceira</class>
<class>br.com.majorEnterpriseJourney.model.Origem</class>
<class>br.com.majorEnterpriseJourney.model.PacoteTuristico</class>
<class>br.com.majorEnterpriseJourney.model.PacoteTuristicoEvento</class>
<class>br.com.majorEnterpriseJourney.model.PassagemAerea</class>
<class>br.com.majorEnterpriseJourney.model.Reserva</class>
<class>br.com.majorEnterpriseJourney.model.Seguradora</class>
<class>br.com.majorEnterpriseJourney.model.Usuario</class>
</persistence-unit>
</persistence>
Tive alguns problemas de mapeamento por estar usando a classe GenericModel e as demais classes do pacote model extenderem dela no projeto
@MappedSuperclass
public class GenericModel {
@Id
@GeneratedValue
private Long id;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (getClass() != obj.getClass()) {
return false;
}
final GenericModel other = (GenericModel) obj;
if (id != other.id && (id == null || !id.equals(other.id))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 17 * hash + (this.getId() != null ? this.getId().hashCode() : 0);
return hash;
}
}
Agora estou com este erro que está difícil encontrar a solução.
-
Error notifying InjectionListener br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor@5950a15f of br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.
Reason: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.bindToConstructor(GuiceComponentRegistry.java:151)
while locating br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator
Caused by: net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method create
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:45)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withoutArgs(MethodHandlerByMethod.java:58)
at br.com.caelum.vraptor.ioc.guice.ScopeLifecycleListener$LifecycleExecutor.afterInjection(ScopeLifecycleListener.java:89)
at com.google.inject.internal.MembersInjectorImpl.notifyListeners(MembersInjectorImpl.java:97)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:95)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:65)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:204)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:198)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:198)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:179)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:83)
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:119)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:113)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791)
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-elt.1: Cannot find the declaration of element ‘persistence’.
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:147)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:171)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:324)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.getEntityManagerFactory(EntityManagerFactoryCreator.java:37)
at br.com.majorEnterpriseJourney.infra.EntityManagerFactoryCreator.create(EntityManagerFactoryCreator.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
… 35 more