当前位置:网站首页 > R语言数据分析 > 正文

spring 教程(spring 教程 推荐)



  • Spring Boot 简介
  • 微服务
  • 环境准备

    • maven设置
    • IDEA设置

  • 使用SpringBoot创建一个HellWorld应用

    • 1、创建一个maven工程(spring-boot-01-helloworld)
    • 2、在pom.xml中导入spring boot相关的依赖
    • 3、编写一个主程序
    • 4、编写相关的Controller
    • 5、运行主程序

  • 简化部署

Spring Boot 简介

       Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。

  • 简化Spring应用开发的一个框架
  • 整个Spring技术栈的一个大整合
  • J2EE开发的一站式解决方案

微服务

微服务:每一个功能元素最终都是一个可独立替换和独立升级的软件单元。

详情参考:微服务文档

环境准备

  • jdk1.8:Spring Boot 推荐jdk1.7及以上
  • maven3.x:maven 3.3以上版本
  • IntelliJIDEA:或者STS
  • SpringBoot 1.5.9.RELEASE:1.5.10

在maven 的settings.xml配置文件的profiles标签添加以下配置:

<profile> <id>jdk‐1.8id> <activation> <activeByDefault>trueactiveByDefault> <jdk>1.8jdk> activation> <properties> <maven.compiler.source>1.8maven.compiler.source> <maven.compiler.target>1.8maven.compiler.target> <maven.compiler.compilerVersion>1.8maven.compiler.compilerVersion> properties> profile>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

把maven整合到idea。
SpringBoot入门教程(超详细)_SpringBoot

使用SpringBoot创建一个HellWorld应用

功能:浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串

项目目录:
SpringBoot入门教程(超详细)_SpringBoot_02

<parent> <artifactId>spring-boot-dependenciesartifactId> <groupId>org.springframework.bootgroupId> <version>1.5.10.RELEASEversion> parent> <dependencies> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-webartifactId> dependency> dependencies>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

HelloWorldMainApplication:

package com.keafmd; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /  * Keafmd  *  * @ClassName: HelloWorldMainApplication  * @Description: 主程序  * @author: 牛哄哄的柯南  * @date: 2021-02-22 15:00  */ @SpringBootApplication public class HelloWorldMainApplication { public static void main(String[] args) { //Spring应用启动起来         SpringApplication.run(HelloWorldMainApplication.class,args); } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

HelloController:

package com.keafmd.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /  * Keafmd  *  * @ClassName: HelloController  * @Description:  * @author: 牛哄哄的柯南  * @date: 2021-02-22 15:04  */ @Controller public class HelloController { @ResponseBody @RequestMapping("/hello") public String hello(){ return "Hello World!"; } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

SpringBoot入门教程(超详细)_SpringBoot_03
运行结果:
SpringBoot入门教程(超详细)_SpringBoot_04
打开浏览器访问:http://localhost:8080/hello
SpringBoot入门教程(超详细)_SpringBoot_05



OK,至此,第一个SpringBoot的HelloWorld就大功告成了。【amazing~】

简化部署

1、我们在pom.xml文件中假如以下代码:

 <build> <plugins> <plugin> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-maven-pluginartifactId> <executions> <execution> <goals> <goal>repackagegoal> goals> execution> executions> plugin> plugins> build>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

2、然后,我们将应用打包
SpringBoot入门教程(超详细)_SpringBoot_06
3、然后再target文件夹下就可以看到spring-boot-01-helloworld-1.0-SNAPSHOT.jar
SpringBoot入门教程(超详细)_SpringBoot_07
4、复制到桌面(随便哪,个人选择),打开cmd窗口,切换到jar包所在位置,我的是桌面,然后输入:java -jar spring-boot-01-helloworld-1.0-SNAPSHOT.jar,运行效果如下。SpringBoot入门教程(超详细)_SpringBoot_08
5、打开浏览器访问:http://localhost:8080/hello,同样可以看到HelloWord
SpringBoot入门教程(超详细)_SpringBoot_05





这样的部署就变得十分简单了。

以上就是SpringBoot入门教程(超详细)的全部内容。

到此这篇spring 教程(spring 教程 推荐)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • ewma模型Excel(ewma模型和garch的区别)2026-02-20 07:18:09
  • nrm安装成功但是不是内外命令(npm已经安装模块但是找不到)2026-02-20 07:18:09
  • yarn查看历史任务列表(如何查看yarn上任务使用的资源)2026-02-20 07:18:09
  • msvcp140无法执行代码(msvcr120.dll无法继续执行代码)2026-02-20 07:18:09
  • spring教程 csdn(spring教程推荐)2026-02-20 07:18:09
  • spring aop实现日志记录(spring aop 日志)2026-02-20 07:18:09
  • argparse模块有什么用(argparse dest)2026-02-20 07:18:09
  • treeswap官网(treetop helper官网)2026-02-20 07:18:09
  • torna di tito a lato谱子(tornamia vagheggiar正谱)2026-02-20 07:18:09
  • oracle查看锁表用户ip(oracle如何查看锁表的语句)2026-02-20 07:18:09
  • 全屏图片