spring-boot2 从零单排(一) 安装与hello world

    好几年没搞web,变化还挺大的。。偶然看了下spring-boot介绍,整个想起当年搭建spring应用的悲催,不竟感慨程序员

的伟大,这他喵就是一神器啊哭     大哥~~spring-boot了解一下!!!!网上一堆介绍它的我不介绍了。


    一:getting-started-installing-spring-boot(安装)
  1.  首先进入spring-boot的getstart页面 地址:点击打开链接 ,找到Maven 安装指导(不用maven的自己去找,擦)
  2. 用ide新建一个maven项目(maven版本上面写着只支持3.2以上,没事可以皮一下看3.2以下能不能构建出来~呵呵),目录大概是这样的
  3. Maven 安装指导有一个叫典型的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.example</groupId>
    	<artifactId>myproject</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    
    	<!-- Inherit defaults from Spring Boot -->
    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>2.1.0.BUILD-SNAPSHOT</version>
    	</parent>
    
    	<!-- Add typical dependencies for a web application -->
    	<dependencies>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    		</dependency>
    	</dependencies>
    
    	<!-- Package as an executable jar -->
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-maven-plugin</artifactId>
    			</plugin>
    		</plugins>
    	</build>
    
    	<!-- Add Spring repositories -->
    	<!-- (you don't need this if you are using a .RELEASE version) -->
    	<repositories>
    		<repository>
    			<id>spring-snapshots</id>
    			<url>https://repo.spring.io/snapshot</url>
    			<snapshots><enabled>true</enabled></snapshots>
    		</repository>
    		<repository>
    			<id>spring-milestones</id>
    			<url>https://repo.spring.io/milestone</url>
    		</repository>
    	</repositories>
    	<pluginRepositories>
    		<pluginRepository>
    			<id>spring-snapshots</id>
    			<url>https://repo.spring.io/snapshot</url>
    		</pluginRepository>
    		<pluginRepository>
    			<id>spring-milestones</id>
    			<url>https://repo.spring.io/milestone</url>
    		</pluginRepository>
    	</pluginRepositories>
    </project>

复制这一段到我们工程下的pom.xml下面

<!-- Inherit defaults from Spring Boot -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.0.BUILD-SNAPSHOT</version>
	</parent>

	<!-- Add typical dependencies for a web application -->
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>

	<!-- Package as an executable jar -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

	<!-- Add Spring repositories -->
	<!-- (you don't need this if you are using a .RELEASE version) -->
	<repositories>
		<repository>
			<id>spring-snapshots</id>
			<url>https://repo.spring.io/snapshot</url>
			<snapshots><enabled>true</enabled></snapshots>
		</repository>
		<repository>
			<id>spring-milestones</id>
			<url>https://repo.spring.io/milestone</url>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>spring-snapshots</id>
			<url>https://repo.spring.io/snapshot</url>
		</pluginRepository>
		<pluginRepository>
			<id>spring-milestones</id>
			<url>https://repo.spring.io/milestone</url>
		</pluginRepository>
	</pluginRepositories>

复制完等工程安装完依赖包就可以编写hello world(这个版本号可以稍微关注一下)

	<version>2.1.0.BUILD-SNAPSHOT</version>
二: hello world 

  1. 建一个新的java 类,重新查看引导页(懒人复制)。。。。。。。。。。。。。。。。。。。。。。。。。。。
  2. 关于注解@RestController..下次再研究,运行应用成功打印:
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v2.1.0.BUILD-SNAPSHOT)

     在网页上输入: http://127.0.0.1:8080/ 成功打印:Hello World!

三、Spring Boot包含一组额外的工具,可以使应用程序开发体验更愉快(传说中的热部署?????)
<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-devtools</artifactId>
		<optional>true</optional>
	</dependency>
    (注IDE必须打开自动编译)intellij idea为例
1、
2、组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”
搞定!!!!!!!!果然,修改helloworld不用重新启动就编译了,感动得痛哭流涕!!!


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值