spring-boot - 我应该如何在 Spring Boot 中设置我的 jsp 文件夹?
问题描述
我在 spring.io 中下载了一个 spring 项目。但是,我找不到 webapp 文件夹。但是,有静态和模板文件夹。有人可以教我如何以编程方式创建 WebMvcConfigurer 和 Servelet 并使用 tomcat 运行它吗?谢谢你。
解决方案
这实际上是一个非常好的问题。
简短的回答:
src/main/resources/META-INF/resources/WEB-INF/jsp
更长的答案:
我最近花了一些时间尝试让 Spring Boot 与 JSP 一起工作,并发现我必须调整几件事:
build.gradle(或等效的 pom.xml):
dependencies { compile('org.springframework.boot:spring-boot-starter-web') compile('javax.servlet:jstl') compile('javax.servlet:javax.servlet-api') compile('org.apache.tomcat.embed:tomcat-embed-jasper') // compile('org.springframework.boot:spring-boot-starter-thymeleaf') // DISABLE THYMELEAF compile('org.webjars:bootstrap:4.1.0') ...
更新 .jsp 的主类和 application.properties
Test7Application.java(主类):
@SpringBootApplication public class Test7Application extends SpringBootServletInitializer { ... @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Test7Application.class); } public static void main(String[] args) { SpringApplication.run(Test7Application.class, args); } ...
应用程序属性:
# Look here for jsp URLs: spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp
根据需要分配控制器路由。
我的完整笔记在这里:
https://github.com/paulsm4/HelloSpringBoot/tree/master/test7
我希望这会有所帮助...
推荐阅读
- android - 手势 - 控制音量和亮度
- maven - 如何构建maven ear资源
- asp.net - Option Strict 设置为 ON 后期绑定问题
- macos - qt 5.8 os x 在 GUI 应用程序打开时捕获传递的参数
- css - 悬停时的 CSS / SVG 缩放效果导致图像从其位置移动
- javascript - 将 .txt 文件打印成 html
- swift - controlTextDidEndEditing 在 NSTableView 加载时被调用
- ruby - 将数组元素添加到嵌套循环中
- javascript - 代码未按顺序执行
- php - 访问 MySQL 数据库的 PHP 代码不回显