spring boot学习笔记(一)HelloWord

1、Spring Boot简介

简化Spring应用开发的框架
整合了spring的一系列技术栈
J2EE开发的一站式解决方案

2、微服务

微服务最早由Martin Fowler与James Lewis于2014年共同提出,微服务架构风格是一种使用一套小服务来开发单个应用的方式途径,每个服务运行在自己的进程中,并使用轻量级机制通信,通常是HTTP API,这些服务基于业务能力构建,并能够通过自动化部署机制来独立部署,这些服务使用不同的编程语言实现,以及不同数据存储技术,并保持最低限度的集中式管理。
微服务的参考文档http://martinfowler.com/articles/microservices.html

3、spring Boot HelloWord

功能描述 浏览器发送hello请求,响应hello word的字符串

3.1创建maven工程

3.2导入依赖

在pom文件中添加如下依赖

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

引入了spring-boot-starter-parent的父项目,在spring-boot-starter-parent又引入了spring-boot-dependencies,在spring-boot-dependencies定义了一系列的版本号,我们就不需要引入版本号了
spring-boot-starter-web是一个场景启动器,引入了web项目需要的依赖
springBoot
将所有的功能做成了启动器,我们只需要按需引入starter,就可以使用对应的功能

3.3编写主程序

/**
 * 标注是一个Spring Boot的程序,加载spring的默认配置文件
 * @SpringBootApplication 注解包括@SpringBootConfiguration和@EnableAutoConfiguration
 * @SpringBootConfiguration 包括@Configuration表示是一个配置类
 * @EnableAutoConfiguration 表示开启自动配置功能,以前需要配置的东西都由spring boot自动配置
 * @EnableAutoConfiguration 是@AutoConfigurationPackage 和 @Import({AutoConfigurationImportSelector.class})的组合注解
 * @AutoConfigurationPackage 将主配置类的所在包及所有子包里面的组件扫描到spring容器中
 * @Import({AutoConfigurationImportSelector.class}) 导入组件的选择器
 *
 */
@SpringBootApplication
public class LearnspringbootApplication {

    public static void main(String[] args) {
        //启动springBoot应用
        SpringApplication.run(LearnspringbootApplication.class, args);
    }
}

3.4编写Controller

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

3.5测试

在浏览器中输入http://127.0.0.1/hello 有hello word显示

3.6简化部署

在pom文件中添加如下插件

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

然后按照下面步骤打包
springboot打包
springboot打包
springboot打包
springboot打包

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值