The Spring Boot guide says I can get the H2 console but it's not working for me.
http://localhost:8080/h2/ Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Wed Oct 26 12:31:46 BST 2016 There was an unexpected error (type=Not Found, status=404). No message available
I created an application.properties
file as follows
spring.h2.console.enabled=true
spring.h2.console.path=/h2
My project is based on this
The default path /h2-console
doesn't work either.
I found another answer where the problem is solved by adding to Application.java
:
@Bean
public ServletRegistrationBean h2servletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
registration.addUrlMappings("/h2/*");
return registration;
}
Everything in my application.properties
file is ignored. I have tried adding:
spring.datasource.url=jdbc:h2:file:~/portal;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
But the database is still created in memory only.
Check if you set a base path in application.properties.
For example, if you have a setting
server.contextPath=/api
You access the h2 Console under
http://localhost:8080/api/h2-console
Obvious, but that was it for me
Your current location src\main\java\hello\application.properties
is the culprit. For 2 reasons.
src\main\java
are ignoredapplication.properties
in the root or config
directory or taken into account (by default). (See the reference guide). The fix is to simply move your application.properties
to src\main\resources
.
Another possible cause for this problem, is if you're using spring security.
In that case, you may want to add a specific permission to the h2-console URL you defined.
For example, for the default h2-console configuration (without a spring.h2.console.path
property), you will add this inside your WebSecurityConfigurerAdapter extending class:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/h2-console/**").permitAll()
.anyRequest().authenticated();
http.headers().frameOptions().sameOrigin();
}
Please also note that line at the end - http.headers().frameOptions().sameOrigin();
.
It's needed to prevent a Whitelable page error when logging in to the console.
This is described also here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With