I have a springboot application. I thymeleaf dependency. Have the following controller class:
@Controller
public class OSController {
@GetMapping("/search")
public String getSearchForm() {
return "index";
}
}
The index.html is stored under templates in resources. But the page is not loading. It just returns the string "index" on the page. I am using the below dependencies in my application:
// spring-boot
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-configuration-processor'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
I suspect that the oauth might be causing the issue. In my security configuration I have allowed this particular page to be displayed without authentication.
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*"));
configuration.setAllowedMethods(List.of("*"));
configuration.setAllowedHeaders(List.of("*"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity
.headers().frameOptions().disable()
.and()
.csrf(AbstractHttpConfigurer::disable)
.cors()
.and() // added for CORS size use CorsConfiguration source bean config
.authorizeRequests()
.antMatchers("/auth/**").permitAll()
.antMatchers("/search**").permitAll()
.antMatchers("/**", "/auth/logout").authenticated()
.and()
//.userDetailsService(jpaUserDetailsService)
.oauth2ResourceServer().jwt(jwt -> jwt.jwtAuthenticationConverter(new CustomJwtAuthConverter()))
.and()
//.httpBasic(Customizer.withDefaults())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.build();
}
you need to add the following to configuration file
you can refer for the entire config in thymeleaf + spring configuration https://www.thymeleaf.org/doc/tutorials/3.1/thymeleafspring.html