1、创建简单Maven项目,如下

2294494-20210515093550060-1147682705.png

2、删掉src目录

3、修改字符编码,如下

2294494-20210515093558555-471479361.png

4、开启注解处理,如下

2294494-20210515093605822-23866489.png

5、选择编译版本,如下

2294494-20210515093732491-1040200639.png

6、编辑 pom.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.wyx</groupId>
  6. <artifactId>Spring-Cloud</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <packaging>pom</packaging>
  9. <properties>
  10. <project.build.sourceEmcoding>UTF-8</project.build.sourceEmcoding>
  11. <maven.compiler.source>1.8</maven.compiler.source>
  12. <maven.compiler.target>1.8</maven.compiler.target>
  13. <!--对应的版本-->
  14. <spring.boot.dependencies.version>2.4.3</spring.boot.dependencies.version>
  15. <spring.cloud.dependencies.version>2020.0.2</spring.cloud.dependencies.version>
  16. <spring.cloud.alibaba.dependencies.version>2.2.1.RELEASE</spring.cloud.alibaba.dependencies.version>
  17. <mysql.version>8.0.23</mysql.version>
  18. <druid.version>1.2.5</druid.version>
  19. <druid.spring.boot.version>1.2.5</druid.spring.boot.version>
  20. <log4j.version>1.2.17</log4j.version>
  21. <junit.version>4.13</junit.version>
  22. <lombok.version>1.18.20</lombok.version>
  23. <mybatis.spring.boot.version>2.1.4</mybatis.spring.boot.version>
  24. </properties>
  25. <dependencyManagement>
  26. <dependencies>
  27. <!--SpringBoot 依赖-->
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-dependencies</artifactId>
  31. <version>${spring.boot.dependencies.version}</version>
  32. <type>pom</type>
  33. <scope>import</scope>
  34. </dependency>
  35. <!--Spring Cloud 依赖-->
  36. <dependency>
  37. <groupId>org.springframework.cloud</groupId>
  38. <artifactId>spring-cloud-dependencies</artifactId>
  39. <version>${spring.cloud.dependencies.version}</version>
  40. <type>pom</type>
  41. <scope>import</scope>
  42. </dependency>
  43. <!--Spring Cloud Alibaba 依赖-->
  44. <dependency>
  45. <groupId>com.alibaba.cloud</groupId>
  46. <artifactId>spring-cloud-alibaba-dependencies</artifactId>
  47. <version>${spring.cloud.alibaba.dependencies.version}</version>
  48. <type>pom</type>
  49. <scope>import</scope>
  50. </dependency>
  51. <!--Mysql 连接驱动-->
  52. <dependency>
  53. <groupId>mysql</groupId>
  54. <artifactId>mysql-connector-java</artifactId>
  55. <version>${mysql.version}</version>
  56. </dependency>
  57. <!--druid 依赖-->
  58. <dependency>
  59. <groupId>com.alibaba</groupId>
  60. <artifactId>druid</artifactId>
  61. <version>${druid.version}</version>
  62. </dependency>
  63. <!--Spring Boot 启动器-->
  64. <dependency>
  65. <groupId>com.alibaba</groupId>
  66. <artifactId>druid-spring-boot-starter</artifactId>
  67. <version>${druid.spring.boot.version}</version>
  68. </dependency>
  69. <!--Lombok 依赖-->
  70. <dependency>
  71. <groupId>org.projectlombok</groupId>
  72. <artifactId>lombok</artifactId>
  73. <version>${lombok.version}</version>
  74. </dependency>
  75. <!--log4j 依赖-->
  76. <dependency>
  77. <groupId>log4j</groupId>
  78. <artifactId>log4j</artifactId>
  79. <version>${log4j.version}</version>
  80. </dependency>
  81. <!--junit 单元测试 依赖-->
  82. <dependency>
  83. <groupId>junit</groupId>
  84. <artifactId>junit</artifactId>
  85. <version>${junit.version}</version>
  86. </dependency>
  87. <!--Mybatis-spring-boot 启动器-->
  88. <dependency>
  89. <groupId>org.mybatis.spring.boot</groupId>
  90. <artifactId>mybatis-spring-boot-starter</artifactId>
  91. <version>${mybatis.spring.boot.version}</version>
  92. </dependency>
  93. </dependencies>
  94. </dependencyManagement>
  95. <build>
  96. <plugins>
  97. <plugin>
  98. <groupId>org.springframework.boot</groupId>
  99. <artifactId>spring-boot-maven-plugin</artifactId>
  100. <version>2.4.4</version>
  101. <configuration>
  102. <fork>true</fork>
  103. <addResources>true</addResources>
  104. </configuration>
  105. </plugin>
  106. </plugins>
  107. </build>
  108. </project>

创建实体类API

1、在父工程下创建一个空maven项目

2294494-20210515093643234-1729014017.png

  1. springboot扫描文件```@ComponentScan(basePackages = {"com.spring.*"})```
  2. 由此springboot启动类的包必须是项目下的父路径,其他类的包路径必须是其子路径。

即其他所有模块的包路径是springboot启动类的子路径