Um sistema que estava funcionando no TOMCAT, migramos para o wildfly. Subiu sem problemas. Mas queremos conectar ao banco de dados pelo arquivo persistence.xml. O que não foi possível.
Estamos utilizando esta dependência do jpa / spring e o arquivo de configuração para fazer a conexão com o banco de dados.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
</dependency>
Arquivo de configuração:
package br.com.netsoft.config;
import java.util.Properties;
import javax.persistence.EntityManagerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
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;
@EnableJpaRepositories(basePackageClasses = WebConfig.class)
@EnableTransactionManagement
@Configuration
public class JPAConfig {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUsername("postgres");
dataSource.setPassword("63Netsis417");
dataSource.setUrl("jdbc:postgresql://localhost:5432/prefeitura");
dataSource.setDriverClassName("org.postgresql.Driver");
factoryBean.setDataSource(dataSource);
Properties props = new Properties();
props.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
props.setProperty("hibernate.show_sql", "true");
props.setProperty("show_sql", "true");
props.setProperty("hibernate.format_sql", "true");
props.setProperty("hibernate.hbm2ddl.auto", "update");
factoryBean.setJpaProperties(props);
factoryBean.setPackagesToScan("br.com.netsoft");
return factoryBean;
}
@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
}
O que fazer para mudar ?