美文网首页
SpringBoot 父pom搭建

SpringBoot 父pom搭建

作者: P_ursuit | 来源:发表于2017-11-12 14:08 被阅读0次

    SpringBoot官网

    1、父pom配置

    <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">
      <modelVersion>4.0.0</modelVersion>
      <!--父POM文件-->
      <groupId>boot.demo</groupId>
      <artifactId>microboot</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>pom</packaging>
    
      <name>microboot</name>
      <url>http://maven.apache.org</url>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jdk.version>1.8</jdk.version>
      </properties>
    
      <dependencyManagement>
        <dependencies>
    
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.4.RELEASE</version>
            <!--以下两个配置为引用程序版本将有springBoot来进行管理-->
            <type>pom</type> 
            <scope>import</scope>
          </dependency>
    
        </dependencies>
      </dependencyManagement>
    
      <build>
        <finalName>microboot</finalName>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>${jdk.version}</source> <!--源码的JDK版本-->
              <target>${jdk.version}</target>
              <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    

    ​ 2、 建立microboot的子模块(module),建立一个普通的restfull接口,实现同样基础操作的功能,修改子模块的pom文件,追加SpringBoot的Web启动包

     <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    </dependencies>
    

    ​ 3、拷贝SpringBoot官网的启动程序代码,运行测试

    package boot.demo;
    
    /**
     * Created by wangjian on 2017/11/4.
     */
    import org.springframework.boot.*;
    import org.springframework.boot.autoconfigure.*;
    import org.springframework.stereotype.*;
    import org.springframework.web.bind.annotation.*;
    
    @Controller
    @EnableAutoConfiguration
    public class SampleController {
    
        @RequestMapping("/")
        @ResponseBody
        String home() {
            return "Hello World!";
        }
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(SampleController.class, args);
        }
    }
    

    ​ 4、启动成功后访问:http://localhost:8080,即可看到返回的“Hello World!”

    在这样的状态下,才可以进行后续的代码编写

    相关文章

      网友评论

          本文标题:SpringBoot 父pom搭建

          本文链接:https://www.haomeiwen.com/subject/vngnmxtx.html