上一节的代码是spring-boot的入门程序,也是官方文档上的一个程序。这一节会引入spring-boot官方文档推荐的方式来开发代码,并引入我们在spring开发中service层等的调用。

1、代码结构如下

第二章 第二个spring-boot程序

2、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 http://maven.apache.org/maven-v4_0_0.xsd">
 4 
 5     <modelVersion>4.0.0</modelVersion>
 6 
 7     <groupId>com.xxx</groupId>
 8     <artifactId>myboot</artifactId>
 9     <version>1.0-SNAPSHOT</version>
10 
11     <properties>
12         <java.version>1.8</java.version><!-- 官方推荐 -->
13     </properties>
14     <!-- 引入spring-boot-starter-parent做parent是最好的方式, 
15          但是有时我们可能要引入我们自己的parent,此时解决方式有两种: 
16          1)我们自己的parent的pom.xml的parent设为spring-boot-starter-parent(没有做过验证,但是感觉可行) 
17          2)使用springboot文档中的方式:见spring-boot-1.2.5-reference.pdf的第13页 
18     -->
19     <parent> 
20         <groupId>org.springframework.boot</groupId> 
21         <artifactId>spring-boot-starter-parent</artifactId> 
22         <version>1.2.5.RELEASE</version> 
23     </parent>
24 
25     <!-- <dependencyManagement>
26         <dependencies>
27             <dependency>
28                 Import dependency management from Spring Boot
29                 <groupId>org.springframework.boot</groupId>
30                 <artifactId>spring-boot-dependencies</artifactId>
31                 <version>1.2.5.RELEASE</version>
32                 <type>pom</type>
33                 <scope>import</scope>
34             </dependency>
35         </dependencies>
36     </dependencyManagement> -->
37 
38     <!-- 引入实际依赖 -->
39     <dependencies>
40         <dependency>
41             <groupId>org.springframework.boot</groupId>
42             <artifactId>spring-boot-starter-web</artifactId>
43         </dependency>
44     </dependencies>
45 
46     <build>
47         <plugins>
48             <!-- 用于将应用打成可直接运行的jar(该jar就是用于生产环境中的jar) 值得注意的是,如果没有引用spring-boot-starter-parent做parent, 
49                 且采用了上述的第二种方式,这里也要做出相应的改动 -->
50             <plugin>
51                 <groupId>org.springframework.boot</groupId>
52                 <artifactId>spring-boot-maven-plugin</artifactId>
53             </plugin>
54         </plugins>
55     </build>
56 </project>
View Code

相关文章:

  • 2021-05-20
  • 2021-08-26
  • 2021-11-11
  • 2018-01-17
  • 2021-10-05
  • 2021-10-30
  • 2021-05-31
猜你喜欢
  • 2021-11-13
  • 2022-01-03
  • 2021-08-10
  • 2021-07-15
  • 2021-11-05
  • 2021-07-20
  • 2021-07-12
相关资源
相似解决方案