Arquivo spring-context.xml

2 respostas
guilhermebhte

O que está de errado ?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx.xsd">
	<!-- Contexto do DispatcherServlet: define a infraestrutura do processamento 
		das requisições feitas ao Servlet (DispatcherServlet) -->
	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="DEVMEDIA-UP" />
		<property name="dataSource" ref="postgresDataSource" />
		<property name="jpaVendorAdapter">
			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
		</property>
	</bean>
	<bean id="postgresDataSource" class="org.apache.commons.dbcp2.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url"
			value="jdbc:postgres://192.168.56.101/des_if_uft_8?createDatabaseIfNotExist=true" />
		<property name="username" value="postgres" />
		<property name="password" value="1234" />
	</bean>
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
	</bean>
	<tx:annotation-driven />
	<!-- Define o pacote base para o escaneamento das anotações de contexto 
		(@Component, @Repository, @Service, @Controller, etc) -->
	<context:component-scan base-package="br.com.amis" />
	<context:annotation-config />
</beans>

Exceção

ADVERTÊNCIA: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name entityManagerFactory defined in class path resource [spring-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: DEVMEDIA-UP] Unable to build EntityManagerFactory

Exception in thread main org.springframework.beans.factory.BeanCreationException: Error creating bean with name entityManagerFactory defined in class path resource [spring-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: DEVMEDIA-UP] Unable to build EntityManagerFactory

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)

at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)

at br.com.amis.run.Run.main(Run.java:15)

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: DEVMEDIA-UP] Unable to build EntityManagerFactory

at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)

at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)

at org.springframework.orm.jpa.vendor.SpringHibernateEjbPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateEjbPersistenceProvider.java:51)

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

 12 more

Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)

at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)

at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:381)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1746)

at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:94)

at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)

 18 more

Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)

at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)

at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:341)

at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:505)

at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:146)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)

 23 more

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)

 32 more

Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property id in class br.com.amis.model.UsuarioEntity

at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)

at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)

at org.hibernate.mapping.Property.getSetter(Property.java:325)

at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444)

at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:182)

at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:82)

 37 more

2 Respostas

Daniel_Dias

Este artigo , tem um spring-context.xml com JPA

esse tambem tem :

http://www.ciceroednilson.com.br/criando-uma-aplicacao-com-spring-mvc-angularjs-jpa-e-wildfly-parte-1-montando-a-estrutura-do-projeto/

{ },.s

guilhermebhte

Obrigado @Daniel_Dias, vou analisar mais tarde e coloco o resultado aqui.

Criado 19 de janeiro de 2017
Ultima resposta 19 de jan. de 2017
Respostas 2
Participantes 2