spring-boot - Spring Boot 无法检索 html 页面
问题描述
我无法通过尝试 localhost:8080/blog 来检索 blog.html 和其他 html。当我尝试访问 /blog 路径时,我得到 Whitelabel 错误页面,因此找不到它的 404,并且在控制台日志中我看到“ ResourceHttpRequestHandler : Path represents URL or has "url:" prefix: [classpath:/templates/blog.html]
”警告。当我将@controller 更改为@restcontroller 时,我可以访问/blog 路径,但使用@controller 我无法访问它。先感谢您
我的项目结构:
Testt.java 所以我的控制器类:
@Controller public class Testt {
@GetMapping(path = "/blog") public String getAbout() { return "blog"; }
}
SecurityConfig.java 所以我的 spring 安全配置类:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests().antMatchers(HttpMethod.GET).permitAll();
}
}
EstoreAppApplication.java 所以我的 boostrapper springbootjava 类:
@SpringBootApplication
public class EstoreAppApplication {
public static void main(String[] args) {
SpringApplication.run(EstoreAppApplication.class, args);
}
}
我的应用程序属性:
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
解决方案
只是一个猜测,因为你没有提到你的 pom.xml 文件,但是:
- 确保其中包含以下依赖项,我假设您缺少模板库,我在这里选择 Thymeleaf。
.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
删除
spring.mvc.view.
属性。再试一次。
推荐阅读
- php - php FLOCK 可以在负载平衡的 Web 服务器上工作吗?
- python - 以最佳方式将字典列表与字典列表转换为数据框 - 雅虎财经
- ios - 使用 Django 发送 iOS 推送通知:基于 HTTP/2 的 APNs 提供程序 API 和二进制协议
- java - Hashmap 并发问题
- html - 将 2 个饼图并排放置
- c - 使用 malloc 在函数中返回一个 int 数组
- python - 输入形状为 [?,1,2,36], [5,5,36,48] 的“conv2d_7/Conv2D”(操作:“Conv2D”)从 1 中减去 5 导致的负尺寸大小
- reactjs - React 中需要 Antd 单选按钮
- jsf - 从外部事件更改字体大小下拉值选择
- c# - 如何使用 SQL 表中的数据填充 html 页面