springboot项目搭建(一)

来源:互联网 发布:禁止安装软件的软件 编辑:程序博客网 时间:2024/05/23 19:21
一、创建maven聚合工程
     这个比较简单,就不在此赘述了。
     给出结构图:
         

二、配置pom文件
     1.配置setting文件(这个不是本文重点,也就先不多说了)
     2.配置pom文件
          a.pom文件一般主要需要配置一下几个部分:
               
          b.因为现在只是简单的搭建一个Hello Word类似的web项目,所以,以上内容就需要简单配置一下即可。
          首先,需要配置父项目的信息和当前项目的属性信息。
               
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
  </parent>

  <!-- 项目属性 -->
  <groupId>com.demo</groupId>
  <artifactId>QQ</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>QQ</name>
  <description>DUBBO-TEST</description>

          然后配置springboot项目所依赖的核心包
 
    <dependencies>
        <!-- spring boot的核心包 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

三、创建应用程序类

package com.summer.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WebApplication {


    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }
}

说明:应用程序类,放在业务类所在包的同级,这样才能使得业务类被扫描到。具体,如图一所示。

四、创建业务类
     
package com.summer.test.web.controller.test;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SummerTest {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    @RequestMapping("/hello/{myName}")
    String index(@PathVariable String myName) {
        return "Hello " + myName + "!!!";
    }
}

五、启动应用程序类


六、浏览器访问, 输入http://localhost:8080



总结:初次接触springboot,在具体的项目中总是依赖了很多的jar包,导致,我对springboot的核心jar包不清楚,故通过此例来验证jar包的功能。当然,仅通过一个例子,并不能说明说明问题,期待后续的继续学习吧。
原创粉丝点击