0
I am creating an application using Spring Boot with JPA. When I go up the application, the following message is launched:
Description: Cannot 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 (no profiles are Currently active).
Okay, I googled and found a topic from Stackoverflow himself (reply link here), talking to set up the application.properties
which DataSource
will be used. However, I do not want to do directly in this file, because I want to set the 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();
}
}
The annotation @Configuration
should not be "calling" Springboot to this class in order to make the configuration of DataSource
?
The way I’m doing it is right, or should use the application.properties?
Someone????
Man, I’m sorry, I just forgot to answer my own question. The problem dates because my main class, which contains Bootapplication, by my carelessness, was not in the root package of the project. Therefore, he could not read my configuration class posted above. But thank you for your reply.
– Cristiano Bombazar
@Cristianobombazar, could you answer your question and mark it as correct? That way other people will know that it’s been solved and how did you solve the problem
– Denis Rudnei de Souza
@Denisrudneidesouza Feito. Thank you!
– Cristiano Bombazar