spring-boot 框架安装配置

本文档详细介绍了如何使用 Maven 创建 Spring Boot 工程,并通过具体步骤指导读者完成项目的搭建及运行,包括创建项目结构、配置 POM 文件、编写 Controller 和启动类等。

一.基本信息

     源码仓库:https://github.com/spring-projects/spring-boot

     帮助文档:https://spring.io/guides/gs/spring-boot/

二.快速开始

      1.通过maven创建一个工程

mvn archetype:generate -DgroupId=com.hippo -DartifactId=AppDemo -DarchetypeArtifactId=maven-archetype-webapp

    2.创建一个package包目录

      mkdir -p src/main/java/hello

    3.配置一下pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>com.hippo</groupId>
    <artifactId>AppDemo</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>

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

    <properties>
        <java.version>1.8</java.version>
    </properties>


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

</project>

4.创建一个contrller文件

   touch src/main/java/hello/HelloController.java

  

package hello;

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

@RestController
public class HelloController {

    @RequestMapping("/")
    public String index() {
        return "Greetings from Spring Boot!";
    }

}

  5. 创建一个Application 启动文件

   touch src/main/java/hello/Application.java

package hello;

import java.util.Arrays;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {

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

 

}

 6.启动

mvn package && java -jar target/AppDemo.jar

7.访问

$ curl localhost:8080
Greetings from Spring Boot!

转载于:https://my.oschina.net/guoenzhou/blog/1557420

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值