Reputation: 3891
I'm using Spring Boot 1.4.1 with the H2 database. I have enabled the H2 console as described in the reference guide by adding the following lines to my application.properties file:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
When I go to the H2 console in Chrome 53 for Windows, I can see the login page and clicking the "Test Connection" button results in "Test successful":
But when I click on the "Connect" button, the screen turns completely blank. When I view the source, I see "Sorry, Lynx not supported yet" (see the full source). The same thing happens in Firefox.
Why is that happening? I believe I am using the correct JDBC URL, as 4 different people posted on this question that you should use jdbc:h2:mem:testdb
.
Upvotes: 49
Views: 23948
Reputation: 11304
For SpringBoot >= 3.x.x you can use
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.annotation.web.configurers.SessionManagementConfigurer;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
private static final String[] EXCLUDED_PATTERNS = {
"/h2-console/**"
};
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.headers(headers -> headers.frameOptions(frameOptionsConfig -> {
frameOptionsConfig.disable();
frameOptionsConfig.sameOrigin();
}));
return http.build();
}
}
Upvotes: 2
Reputation: 5649
Along with the answer by @pacoverflow note the following:
As of Spring Boot 2.3.4. The DB Name is printed in the console:
Connect using that DB name:
Upvotes: -1
Reputation: 910
I can resolve the same problem using the following code in my SecurityConfig class
@Override
protected void configure(HttpSecurity http) throws Exception {
bla();
bla();
http.headers().frameOptions().sameOrigin();
}
I don't know what this line does, maybe someone with more experience can explain it.
Upvotes: 8
Reputation: 528
Add this to your application.properties
security.headers.frame=false
Upvotes: 0
Reputation: 3891
According to a blog post, a line needs to be added to
the configure
method of the SecurityConfig
class if you have the spring-boot-starter-security
dependency in your project, otherwise you will see an empty page after logging into the H2 console:
http.headers().frameOptions().disable();
I added that line and it solved the problem.
Alternatively, the following line can be used (as mentioned here):
http.headers().frameOptions().sameOrigin();
Upvotes: 96