How to deploy swagger generated spring code (Tomcat)
我使用了SwaggerCodeGen给出的示例通过SpringBoot创建服务器。
我使用Maven构建项目并在本地运行。 一切正常。
现在,我想将此项目部署在tomcat(版本7)上。
所以我把包装从罐子改为战争
1 | <packaging>war</packaging> |
并将* .war文件移动到tomcat \ webapps文件夹
我试着跑
localhost:8080/app
返回404
与...相同
localhost:8080/app/swagger-ui.html
localhost:8080/v1/app/
localhost:8080/v1/app/api-docs
不幸的是,我没有tomcat的经验。
该项目不包含web.xml。 有必要吗?
我需要创建一个Servlet吗?
任何帮助,将不胜感激。
在您的POM中,您需要:
1 2 3 4 5 | <dependency> <groupId>org.springframework.boot</groupId> spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> |
和
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> spring-boot-maven-plugin</artifactId> <version>1.5.9</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> maven-war-plugin</artifactId> <version>3.0.0</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> |
您的SpringBoot应用程序也应如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 | public class SpringBootServiceApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringBootServiceApplication .class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SpringBootServiceApplication .class); } } |