我在spring.io下载了一个spring项目。但是,我找不到webapp文件夹。但是,有静态和模板文件夹。有人可以教我如何以编程方式创建WebMvcConfigurer和Servelet并使用tomcat运行它吗?谢谢。
这实际上是一个非常好的问题。
简短的回答:
src/main/resources/META-INF/resources/WEB-INF/jsp
更长的答案:
我最近花了一些时间试图让Spring Boot使用JSP,并发现我必须调整几件事:
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')
...
@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
我的完整笔记在这里:
https://github.com/paulsm4/HelloSpringBoot/tree/master/test7
我希望有帮助......