I'm creating an application using Spring Boot with JPA. When I upload the application, the following message is displayed:
Description: Can not determine embedded database driver class for database type NONE Action: If you want an embedded database please put a supported one on the classpath. > If you have database settings to be loaded from a particular profile you may> need to active it.
Ok, I looked it up in Google and found a topic from StackOverFlow itself (answer link here) , speaking to set application.properties
which DataSource
will be used. However, I do not want to do this directly, since I want to set DataSource
directly in the application.
My class:
@Configuration
@EnableJpaRepositories("br.com.sys.dao")
@EnableTransactionManagement
public class JpaConfig {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
DataSource ds = dataSource();
ConnectionManager.getInstance().setDataSource(ds);
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "validate");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
properties.setProperty("hibernate.show_sql", "false");
properties.setProperty("hibernate.format_sql", "false");
properties.setProperty("hibernate.use_sql_comments", "false");
properties.setProperty("hibernate.physical_naming_strategy", "br.com.sys.configuration.LowercaseNamingStrategy");
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(ds);
em.setPackagesToScan("br.com.sys.model");
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setJpaProperties(properties);
return em;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/bd");
dataSource.setUsername("postgres");
dataSource.setPassword("postgres");
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
}
Should not the @Configuration
annotation be "calling" SpringBoot for this class to be able to configure DataSource
?
Is the way I'm doing correct, or should I use application.properties?
Someone ????