org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class br.com.casadocodigo.loja.conf.JPAConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean br.com.casadocodigo.loja.conf.JPAConfiguration.entityManagerFactory()] threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
Classes
package br.com.casadocodigo.loja.conf;
import java.util.Properties;
import javax.persistence.EntityManagerFactory;
import org.springframework.context.annotation.Bean; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement public class JPAConfiguration {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
factoryBean.setJpaVendorAdapter(vendorAdapter);
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUsername("system");
dataSource.setPassword("bancooracle");
dataSource.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
factoryBean.setDataSource(dataSource);
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle12cDialect");
properties.setProperty("hibernate.show_sql", "true");
properties.setProperty("hibernate.hbm2ddl.auto", "update");
factoryBean.setJpaProperties(properties);
factoryBean.setPackagesToScan("br.com.casadocodigo.loja.models");
return factoryBean;
}
@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
}
@Override protected Class<?>[] getServletConfigClasses() { return new Class[] {AppWebConfiguration.class, JPAConfiguration.class};
}
package br.com.casadocodigo.loja.models;
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator; import javax.persistence.Table;
@Entity @Table(name = "T_CS_PRODUTO") @SequenceGenerator(name = "produto" ,sequenceName = "T_SQ_PRODUTO" ,allocationSize = 1) public class Produto {
@Id
@GeneratedValue(generator = "produto" ,strategy = GenerationType.SEQUENCE)
@Column(name = "cd_produto")
private int id;
@Column(name = "nm_produto" ,nullable = false)
private String titulo;
@Column(name = "ds_produto")
private String descricao;
@Column(name = "nr_paginas")
private int paginas;
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public int getPaginas() {
return paginas;
}
public void setPaginas(int paginas) {
this.paginas = paginas;
}
@Override
public String toString() {
return "Produto [titulo=" + titulo + ", descricao=" + descricao + ", paginas=" + paginas + "]";
}
}
E TAMBEM TENHO O DRIVER ORACLE NO MEU POM.ALGUEM ME AJUDA?