如何在spring boot中设置我的jsp文件夹?

问题描述 投票:0回答:1

我在spring.io下载了一个spring项目。但是,我找不到webapp文件夹。但是,有静态和模板文件夹。有人可以教我如何以编程方式创建WebMvcConfigurer和Servelet并使用tomcat运行它吗?谢谢。

spring-boot model-view-controller servlet-3.0
1个回答
0
投票

这实际上是一个非常好的问题。

简短的回答:

src/main/resources/META-INF/resources/WEB-INF/jsp

更长的答案:

我最近花了一些时间试图让Spring Boot使用JSP,并发现我必须调整几件事:

  1. 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') ...
  2. 更新.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); } ... application.properties: # Look here for jsp URLs: spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp
  3. 根据需要分配控制器路由。

我的完整笔记在这里:

https://github.com/paulsm4/HelloSpringBoot/tree/master/test7

我希望有帮助......

© www.soinside.com 2019 - 2024. All rights reserved.