手动创建一个最简单的maven-springboot项目

maven_springboot

我们可能经常需要建立一个简单的web项目测试,而手边又没有或时不想那么麻烦使用IDE工具。这是我们可以使用maven+springboot建立一个最简单的web项目,对外提供简单的REST之类的接口。

创建maven目录结构

  1. 新建一个项目文件夹springboot_test;
  2. 在项目根目录下新建代码目录src/main/java/com/yihengliu/sprintboottest/controller;
  3. 在项目根目录下新建资源目录src/main/resources;

结构目录:

.
├── pom.xml
└── src
    └── main
        ├── java
        │   └── com
        │       └── yihengliu
        │           └── springboottest
        │               ├── controller
        └── resources

编写pom.xml文件

在项目根目录下新建pom.xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.yihengliu</groupId>
    <artifactId>springboot_test</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>          

编写运行类和Controller类

  1. 目录src/main/java/com/yihengliu/springboottest/下编写运行类SpringbootTestApplication.java

    package com.yihengliu.springboottest;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class SpringbootTestApplication {
        public static void main(String[] args) {
            SpringApplication.run(SpringbootTestApplication.class, args);
        }
    }
  2. 目录src/main/java/com/yihengliu/springboottest/controller/下编写Controller类

    package com.yihengliu.springboottest.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * 测试controller
     *
     * @author liucheng
     **/
    @RestController
    public class TestController {
        @RequestMapping("/index")
        public String method() {
            return "return request";
        }
    }

启动测试

  1. 启动项目,在目录根目录运行mvn spring-boot:run

  2. 运行访问
    springboot_test_show

参考代码

点击下载

转载于:https://www.cnblogs.com/liuchengcc/p/8334374.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值