Spring boot cannot retrieve html page

1.5k views Asked by At

I can't retrieve the neither blog.html nor other htmls with trying localhost:8080/blog . When i am trying to access /blog path i get Whitelabel Error Page so its 404 not found and in the console log i am seeing " ResourceHttpRequestHandler : Path represents URL or has "url:" prefix: [classpath:/templates/blog.html]" warning. When i change my @controller to @restcontroller i can access /blog path but with @controller i can't access it . Thank you in advance

my project structure :

enter image description here

Testt.java so my controller class :

@Controller public class Testt {

    @GetMapping(path = "/blog")     public String getAbout() {      return "blog";  }

}

SecurityConfig.java so my spring security config class :

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().authorizeRequests().antMatchers(HttpMethod.GET).permitAll();
    }

}

EstoreAppApplication.java so my boostrapper springbootjava class:

@SpringBootApplication
public class EstoreAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(EstoreAppApplication.class, args);
    }

}

my application properties :

spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
1

There are 1 answers

0
Marco Behler On

Just a guess, as you didn't mention your pom.xml file,but:

  1. Make sure to have the following dependency inside it, I'm assuming you are missing a templating library and I am choosing Thymeleaf here.

.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
  1. Remove the spring.mvc.view. properties.

  2. Try again.