File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
spring-security-modules/spring-security-web-boot-5/src/main
java/com/baeldung/h2blankconsoleerror Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .baeldung .h2blankconsoleerror ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+
6+ @ SpringBootApplication
7+ public class H2Application {
8+
9+ public static void main (String [] args ) {
10+ SpringApplication .run (H2Application .class , args );
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .h2blankconsoleerror .config ;
2+
3+ import static org .springframework .security .config .Customizer .withDefaults ;
4+
5+ import org .springframework .context .annotation .Bean ;
6+ import org .springframework .context .annotation .Configuration ;
7+ import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
8+ import org .springframework .security .config .annotation .web .configurers .HeadersConfigurer ;
9+ import org .springframework .security .web .SecurityFilterChain ;
10+
11+ @ Configuration
12+ public class SecurityConfig {
13+
14+ @ Bean
15+ SecurityFilterChain configure (HttpSecurity http ) throws Exception {
16+ http .csrf (csrf -> csrf .ignoringRequestMatchers ("/h2-console/**" ))
17+ .headers (headers -> headers .frameOptions (HeadersConfigurer .FrameOptionsConfig ::sameOrigin ))
18+ .authorizeHttpRequests (auth -> auth
19+ .anyRequest ().authenticated ())
20+ .formLogin (withDefaults ());
21+
22+ return http .build ();
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ server.port =8080
2+ server.servlet.context-path =/
3+ spring.datasource.url =jdbc:h2:mem:testdb
4+ spring.datasource.driverClassName =org.h2.Driver
5+ spring.datasource.username =sa
6+ spring.datasource.password =password
7+ spring.jpa.database-platform =org.hibernate.dialect.H2Dialect
8+ spring.h2.console.enabled =true
You can’t perform that action at this time.
0 commit comments