Issue
I have a basic SpringBoot app., embedded Tomcat, Thymeleaf template engine. I've created this bean to access the console:
@Bean
public ServletRegistrationBean h2ConsoleServletRegistration() {
ServletRegistrationBean bean = new ServletRegistrationBean(new WebServlet());
bean.addUrlMappings("/console/*");
return bean;
}
I access to the console: http://localhost:8080/appContext/console/login.do?jsessionid=f3585792a9bf1f0cf1a0b6a09dcefe1a
I have my beans annotated as follows:
@Entity
@Table(name="t_user")
public class User implements Serializable, UserDetails {
..
}
My application properties:
# Spring Data JPA properties
spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.H2Dialect
But I don't see any table created by JPA:
Solution
Remove all you have in your properties file. All of those you mentioned are default. Spring-boot will configure it any way as soon as it identifies h2 dependency in your pom. And also you don't need that ServletRegistration
bean. Remove that as well. Just put this in your properties file
spring.h2.console.enabled=true
.
By default console can be accessed on http://localhost:8080/h2-console
, default path is h2-console
. You can configure it using spring.h2.console.path
property.
Answered By - pvpkiran
Answer Checked By - Terry (JavaFixing Volunteer)