I have downloaded a spring project in spring.io. However, I cannot find webapp folder. However, there are static and templates folders. Can someone teach me how to create WebMvcConfigurer and Servelet programmatically and run it using tomcat? Thank you.
答案 0 :(得分:0)
That's actually a very good question.
SHORT ANSWER:
src/main/resources/META-INF/resources/WEB-INF/jsp
LONGER ANSWER:
I recently spent some time trying to get Spring Boot working with JSP, and found that I had to adjust several things:
build.gradle (or equivalently, 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')
...
Update the main class and application.properties for .jsp
Test7Application.java (main class):
@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
Assign controllers routes as needed.
My complete notes are here:
https://github.com/paulsm4/HelloSpringBoot/tree/master/test7
I hope that helps...