简体   繁体   中英

Spring Boot - serving pure html and static content

So far I have spent many hours to done this and still can not figure it out. How to serve pure .html pages. This is the project: https://github.com/robson021/Invoice-Writer

Thymeleaf engine works fine, but if I try to return "regular" .html file I got error.

Whitelabel Error Page (...) There was an unexpected error (type=Internal Server Error, status=500). Exception parsing document: template="test", line 6 - column 3

I acknowledge that this is caused because my "test.html" file does not look like Thymeleaf file. However I tried to remove Thymeleaf form Maven's POM (or create new project form spring initializer in InteliJ, project without Thymeleaf, only Web) and put that .html files into different directories (static, public, WEB-INF) and still failed... I also tried to configure project manually with Java classes. Unfortunetely got 404 or 500 erorros.

Since this is the school project and goal is to make your front-end independet, I want to use pure html with AngularJS. No .jsp or themplate engines.

Can anyone tell me how to make it work is Spring Boot project?

Edit:

my controller:

@Controller
public class TestController {

    @RequestMapping("/test")
    public String goToTestPage() {
        return "test";
    }
}

main class:

@SpringBootApplication
@EnableAutoConfiguration
public class InvoiceWriterApplication {
    public static void main(String\[\] args) {
        SpringApplication.run(InvoiceWriterApplication.class, args);
    }
}

and project structure: http://i.stack.imgur.com/vCqiQ.png

Replace @Controller with @RestController - (or just add @ResponseBody with the @Contorller on the controller class) - to convert a controller into a REST controller.

This is because @Controller annotation alone will result in the return value "home" to be mapped to a template file.

Also for JPA repositories to work you need to use @EnableJpaRepositories .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM