Spring Boot 速览《一》 快速开始

O、README

起码需要了解 Maven的基本使用

IDE 无所谓 idea,eclipse均可

一、我的环境

1、java version "1.8.0_201"

2、Apache Maven 3.5.4

   1) setting.xml 中的设置

<profile>
    <id>jdk-1.8</id>
        <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
</profile>

3、idea 2018.3.3

4、SpringBoot 2.0.5.RELEASE

二、快速开始

PART I - 开发/测试

1、创建一个maven工程(jar) 

2、pom中导入依赖

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

3、编写启动程序


@SpringBootApplication
public class ProcessMainApplication {

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

4、编写Controller

@Controller
public class HelloController {
   
    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World!";
    }
}

5、run 启动程序 ProcessMainApplication.java

6、浏览器访问 http://localhost:8080/hello

PART II - 部署

1、pom.xml

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

2、双击下图 package 开始打包

打出的jar文件 在 target/xxxx.jar

 

3、java -jar xxxx.jar

 

三、其他

https://start.spring.io/ 

可以将上述搭建过程自动化 但还有必要了解这个自动化的过程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值