Sprint Boot 打War包并启动

举报
清雨小竹 发表于 2022/09/24 23:55:54 2022/09/24
【摘要】 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4....

pom.xml


  
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.yunfeng</groupId>
  4. <artifactId>YFEidApi</artifactId>
  5. <version>1</version>
  6. <packaging>war</packaging>
  7. <parent>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter-parent</artifactId>
  10. <version>0.5.0.M7</version>
  11. </parent>
  12. <dependencies>
  13. <dependency>
  14. <groupId>org.springframework.boot</groupId>
  15. <artifactId>spring-boot-starter-web</artifactId>
  16. <!-- 移除嵌入式tomcat插件 -->
  17. <exclusions>
  18. <exclusion>
  19. <groupId>org.springframework.boot</groupId>
  20. <artifactId>spring-boot-starter-tomcat</artifactId>
  21. </exclusion>
  22. </exclusions>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.thymeleaf</groupId>
  26. <artifactId>thymeleaf-spring3</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.apache.tomcat</groupId>
  30. <artifactId>tomcat-servlet-api</artifactId>
  31. <version>9.0.0.M22</version>
  32. <scope>provided</scope>
  33. </dependency>
  34. </dependencies>
  35. <properties>
  36. <start-class>com.eid.controller.App</start-class>
  37. </properties>
  38. <build>
  39. <plugins>
  40. <plugin>
  41. <groupId>org.springframework.boot</groupId>
  42. <artifactId>spring-boot-maven-plugin</artifactId>
  43. </plugin>
  44. <plugin>
  45. <groupId>org.apache.maven.plugins</groupId>
  46. <artifactId>maven-compiler-plugin</artifactId>
  47. <configuration>
  48. <source>1.8</source>
  49. <target>1.8</target>
  50. </configuration>
  51. </plugin>
  52. </plugins>
  53. </build>
  54. <repositories>
  55. <repository>
  56. <id>spring-milestone</id>
  57. <url>http://repo.spring.io/libs-milestone</url>
  58. <snapshots>
  59. <enabled>false</enabled>
  60. </snapshots>
  61. </repository>
  62. </repositories>
  63. <pluginRepositories>
  64. <pluginRepository>
  65. <id>spring-milestone</id>
  66. <url>http://repo.spring.io/libs-milestone</url>
  67. <snapshots>
  68. <enabled>false</enabled>
  69. </snapshots>
  70. </pluginRepository>
  71. </pluginRepositories>
  72. </project>



  
  1. package com.eid.controller;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  4. import org.springframework.context.annotation.ComponentScan;
  5. @ComponentScan
  6. @EnableAutoConfiguration
  7. public class App {
  8. public static void main(String[] args) {
  9. System.out.println("Start App Class....");
  10. SpringApplication.run(App.class, args);
  11. }
  12. }


  
  1. package com.eid.controller;
  2. import org.springframework.boot.builder.SpringApplicationBuilder;
  3. import org.springframework.boot.web.SpringBootServletInitializer;
  4. /**
  5. * 修改启动类,继承 SpringBootServletInitializer 并重写 configure 方法
  6. */
  7. public class SpringBootStartApplication extends SpringBootServletInitializer {
  8. @Override
  9. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  10. // 注意这里要指向原先用main方法执行的Application启动类
  11. return builder.sources(App.class);
  12. }
  13. }



  
  1. package com.eid.controller;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RestController;
  5. @RestController
  6. public class TestController {
  7. @RequestMapping("/t1")
  8. public String showPerson() {
  9. return "test";
  10. }
  11. }


注意:当RestController需要接收参数是需要满足两个条件

1.请求的The request’sContent-Typeheader must be set toapplication/json.

2.The JacksonJSONlibrary must be available on the application’s classpath. 

所以在classpath中添加了一个jar。问题解决了。


  
  1. <dependency>
  2. <groupId>com.fasterxml.jackson.core</groupId>
  3. <artifactId>jackson-databind</artifactId>
  4. <version>2.5.3</version>
  5. </dependency>


文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。

原文链接:zzzili.blog.csdn.net/article/details/77019481

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。