Erro Vraptor + Jboss as 7.1 e JPA

4 respostas
vasilvei

Boa tarde faz dois dias que estou tendo configurar o jboss com a minha aplicaçao que usava tomcat, mas sem sucesso,

eu segui esse tutorial: http://www.messiasbittencourt.com/168/jboss-7-mysql/ a diferença é que o meu banco é postgres, fiz a conexão com o banco no console do Jboss esta acessando de boa,

mas quando executo a minha aplicação da nullpoiter, eu uso Vrapor e hibernate:

persistence.xml:

<?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="Coliseu" transaction-type="JTA">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>  
		<jta-data-source>java:/datasources/Coliseu</jta-data-source>
		
		 <properties>
         <!--    <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="false" /> -->
            <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        </properties>
		
	</persistence-unit>
</persistence>

meu standalone.xml a parte do banco esta assim:

<datasources>
                <datasource jta="true" jndi-name="java:/datasources/Coliseu" pool-name="Coliseu" enabled="true" use-java-context="true" use-ccm="true">
                    <connection-url>jdbc:postgresql://192.168.1.77:5432/coliseuteste</connection-url>
                    <driver>com.postgres</driver>
                    <security>
                        <user-name>coliseu</user-name>
                        <password>coliseu</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
                <drivers>
                    <driver name="com.postgres" module="com.postgres">
                        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>

daí eu tenho as classes CriadorDeEntityManagerFactory para cria a fabrica de conexões:

package br.com.coliseu.resources;

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 CriadorDeEntityManagerFactory implements
		ComponentFactory<EntityManagerFactory> {

	private EntityManagerFactory factory;

	@PostConstruct
	public void abre() {
		factory = Persistence.createEntityManagerFactory("Coliseu");
	}

	public EntityManagerFactory getInstance() {
		return factory;
	}

	@PreDestroy
	public void fecha() {
		this.factory.close();
	}

}

e tenhos a classe que cria as entitymanager:

package br.com.coliseu.resources;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.ComponentFactory;

@Component
public class CriadorDeEntityManager implements ComponentFactory<EntityManager> {

	@PersistenceContext(unitName="Coliseu")
	private EntityManager manager;



	public EntityManager getInstance() {
		// TODO Auto-generated method stub
		return this.manager;
	}

}

Alguém já passou por isso, ou sabe o que estou fazendo de errado?

Obrigado!

4 Respostas

WRYEL

coloque sua exceção aqui pra gente ver.

quando eu configurei a conexão no postgre, eu segui aqui:

https://community.jboss.org/blogs/amartin-blog/2012/02/08/how-to-set-up-a-postgresql-jdbc-driver-on-jboss-7

[]'s

vasilvei
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through constructor argument with index 2 of type [br.com.coliseu.repository.LoginRepository]: : Error creating bean with name 'loginBusiness': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : Error creating bean with name 'br.com.coliseu.resources.CriadorDeEntityManager': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'criadorDeEntityManager': Invocation of init method failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.coliseu.resources.CriadorDeEntityManager': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'criadorDeEntityManager': Invocation of init method failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginBusiness': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : Error creating bean with name 'br.com.coliseu.resources.CriadorDeEntityManager': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'criadorDeEntityManager': Invocation of init method failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.coliseu.resources.CriadorDeEntityManager': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'criadorDeEntityManager': Invocation of init method failed; nested exception is java.lang.NullPointerException
diogogama

To do mesmo jeito…

diogogama

GRAVE: Unhandled exception occurred whilst decorating page org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through constructor argument with index 2 of type [br.com.golfc.business.UsuarioBusiness]: : Error creating bean with name 'usuarioBusiness': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : No matching bean of type [javax.persistence.EntityManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.persistence.EntityManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usuarioBusiness': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : No matching bean of type [javax.persistence.EntityManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.persistence.EntityManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)

Esqueci o código… rs…

Criado 27 de abril de 2012
Ultima resposta 9 de ago. de 2012
Respostas 4
Participantes 3