[英]Spring Boot and plain html
Does anyone tuned spring boot to use as a view plain html without thymeleaf? 有没有人调整过弹簧靴以用作没有百里香叶的纯HTML视图? Here is my configuration:
这是我的配置:
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
@Configuration
@EnableWebMvc
public class WebUi extends WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".html");
return resolver;
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
//
// @Override
// public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
// configurer.enable();
// }
public static void main(String[] args) {
SpringApplication.run(WebUi.class, args);
}
}
I've tried with enabling DefaultServletHandler and without. 我尝试过启用DefaultServletHandler和不启用。 The html file placed in src/main/resources/WEB-INF/login.html and assembled.
将html文件放在src / main / resources / WEB-INF / login.html中并进行组装。 I see it in the classpath in debug.
我在调试的类路径中看到它。 But request to http://localhost:8080/login returns 404. What I'm doing wrong?
但是请求http:// localhost:8080 / login返回404。我在做什么错?
Remove all annotations only leave @SpringBootApplication
. 删除所有注释,仅离开
@SpringBootApplication
。
Remove your InternalResourceViewResolver
and simply add the following to the application.properties
. 删除您的
InternalResourceViewResolver
,只需将以下内容添加到application.properties
。
spring.view.prefix=/WEB-INF/
spring.view.suffix=.html
Your current application class interferes with the Spring Boot auto configuration due to the @EnableWebMvc
. 由于
@EnableWebMvc
您当前的应用程序类会干扰Spring Boot的自动配置。 Next @SpringBootApplication
already implies @Configuration
, @EnableAutoConfiguration
and @ComponentScan
no need to add them again. 接下来的
@SpringBootApplication
已经暗示@Configuration
@EnableAutoConfiguration
, @ComponentScan
@EnableAutoConfiguration
和@ComponentScan
无需再次添加它们。
When adding the spring.view.*
properties Spring Boot already configures a InternalResourceViewResolver
for you. 添加
spring.view.*
属性时,Spring Boot已经为您配置了InternalResourceViewResolver
。
Basic advice here is work with the framework not around/against the framework. 这里的基本建议是在框架周围(而不是在框架周围)使用框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.