[英]Deploy Spring Boot (with JSP) to Elastic Beanstalk
I am attempting to deploy my Spring Boot project to Amazon Elastic Beanstalk.我正在尝试将我的 Spring Boot 项目部署到 Amazon Elastic Beanstalk。 I have tested and have no issue if I use the default Thymeleaf configuration, but when I switch to JSP based setup I get 404's as it cannot find the JSP's (located in src/main/webapp/WEB-INF/jsp)如果我使用默认的 Thymeleaf 配置,我已经测试并且没有问题,但是当我切换到基于 JSP 的设置时,我得到 404,因为它找不到 JSP(位于 src/main/webapp/WEB-INF/jsp)
I have attempted to deploy the sample (spring-boot-sample-tomcat-jsp) and find that this as well gives me a 404 when I run the provided test.我试图部署示例(spring-boot-sample-tomcat-jsp)并发现当我运行提供的测试时这也给了我一个 404。
Here is how I have typically been configuring my Spring Boot Projects to allow for the use of JSP's.以下是我通常如何配置我的 Spring Boot 项目以允许使用 JSP。
Add Jasper and JSTL to pom.xml将 Jasper 和 JSTL 添加到 pom.xml
<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency>
Override default view resolver configuration覆盖默认视图解析器配置
@Configuration @EnableWebMvc public class MvcConfiguration extends WebMvcConfigurerAdapter { @Bean public ViewResolver getViewResolver(){ InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/jsp/"); resolver.setSuffix(".jsp"); return resolver; } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){ configurer.enable(); } }
Create folder for JSP's (src/main/webapp/WEB-INF/jsp)为 JSP 创建文件夹 (src/main/webapp/WEB-INF/jsp)
Now this method works without issue until I deploy to Elastic Beanstalk where I find that no matter if I create a jar and use Java (in Elastic Beanstalk) or create a war and use Tomcat (in eb) I get a 404 when any controller tries to return a view in the WEB-INF/jsp folder.现在这种方法可以正常工作,直到我部署到 Elastic Beanstalk 在那里我发现无论我创建一个 jar 并使用 Java(在 Elastic Beanstalk 中)还是创建一个战争并使用 Tomcat(在 eb 中)当任何控制器尝试时我都会得到 404返回 WEB-INF/jsp 文件夹中的视图。
Is the above method for switching to JSP's not recommended?不推荐使用上述切换到 JSP 的方法吗? Is there a better way to configure Spring Boot to use Tomcat/Jasper/JSP's?有没有更好的方法来配置 Spring Boot 以使用 Tomcat/Jasper/JSP?
I have attempted the method provided in the Spring Boot Samples on github here我在这里尝试了 github 上的 Spring Boot Samples 中提供的方法
But what's interesting is if I run the provided test i get the same 404.但有趣的是,如果我运行提供的测试,我会得到相同的 404。
Any help would be greatly appreciated.任何帮助将不胜感激。 If there is a better way to deploy a Spring Boot project that utilizes JSP's I'd be happy to switch over, but currently I seem to have configured myself into a corner.如果有更好的方法来部署利用 JSP 的 Spring Boot 项目,我很乐意切换,但目前我似乎已经将自己配置到了一个角落。
Thx!谢谢!
I am answering as a novice developer in Springboot development.我作为 Springboot 开发的新手开发人员来回答。 And, I am just playing around with AWS EB and SpringBoot app deployment.而且,我只是在玩 AWS EB 和 SpringBoot 应用程序部署。
Here are my findings,这是我的发现,
The example I tried is inspired from here: https://github.com/in28minutes/deploy-spring-boot-aws-eb/tree/master/03-spring-boot-web-application-h2我尝试的示例来自这里: https ://github.com/in28minutes/deploy-spring-boot-aws-eb/tree/master/03-spring-boot-web-application-h2
Here is the application class that I changed from extending SpringBootServletInitializer to WebMvcConfigurerAdapter, which didn't work and gave me 404. https://github.com/in28minutes/deploy-spring-boot-aws-eb/blob/master/03-spring-boot-web-application-h2/src/main/java/com/in28minutes/springboot/web/SpringBootFirstWebApplication.java这是我从将 SpringBootServletInitializer 扩展为 WebMvcConfigurerAdapter 更改的应用程序类,它不起作用并给了我 404。 https://github.com/in28minutes/deploy-spring-boot-aws-eb/blob/master/03- spring-boot-web-application-h2/src/main/java/com/in28minutes/springboot/web/SpringBootFirstWebApplication.java
Hopefully this helps ...!希望这会有所帮助......!
Still finding out a reason about why we receive 404 when we extend Application class with WebMvcConfigurerAdapter.当我们使用 WebMvcConfigurerAdapter 扩展 Application 类时,仍然找出我们收到 404 的原因。 I Will update this same answer, once I find a reason.一旦找到原因,我将更新相同的答案。
Thank you...!谢谢...!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.