博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot2系列教程(一)简介及HelloWorld项目
阅读量:7145 次
发布时间:2019-06-29

本文共 2597 字,大约阅读时间需要 8 分钟。

Spring Boot 2.0.0.RELEASE 需要 and  或者更高版本. 支持Maven 3.2+和Gradle 4 版本

#####支持的Servlet容器 Tomcat 8.5、Jetty 9.4、Jetty 9.4

####官方版本迁移wiki https://github.com/spring-projects/spring-boot/wiki

####HelloWorld异同项目分析

######1. 修改 pom.xml

4.0.0
springboot-mybatis
springboot-mybatis
0.0.1-SNAPSHOT
jar
springboot-mybatis
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.0.RELEASE
org.springframework.boot
spring-boot-starter-web
junit
junit
test
org.springframework.boot
spring-boot-test
test
org.springframework
spring-test
5.0.4.RELEASE
org.springframework.boot
spring-boot-maven-plugin
复制代码

######2. 修改启动类

package springbootmybatis.springbootmybatis;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@EnableAutoConfigurationpublic class MybatisApplication {	public static void main(String[] args) {		SpringApplication.run(MybatisApplication.class, args);	}	@RequestMapping("/")	String home() {		return "Hello World!";	}}复制代码

######代码中三个注解分析 两个MVC注解:

  1. @RestController 是Spring处理web请求时用到的注解。告诉Spring将结果字符串直接呈现给调用者。
  2. @RequestMapping 提供了“路由”信息,将/请求映射给home()方法。

SpringBoot注解: 3. @EnableAutoConfiguration 这个注解告诉Springboot 根据你添加的jar包来猜测配置Spring 。@SpringBootApplication一样,也可以使用exclude属性来禁用不需要自动配置的应用。例子:@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) 那么,它和@SpringBootApplication注解有什么关系呢? ######我们来看下@SpringBootApplication注解源码

所以,@SpringBootApplication注释是相当于使用@Configuration, @EnableAutoConfiguration以及@ComponentScan与他们的
默认属性

通俗的讲:@SpringBootApplication = @Configuration+@EnableAutoConfiguration+@ComponentScan 。前提是默认配置,当然,如果你想要覆盖默认配置,你就需要重写该注解了,重写也很简单,给注解加上参数就好。

转载地址:http://ppzgl.baihongyu.com/

你可能感兴趣的文章
csharp: word or excel Convert to PDF
查看>>
csharp: Export or Import excel using NPOI
查看>>
一起谈.NET技术,VS 2010 和 .NET 4.0 系列之《多显示器支持》篇
查看>>
“Linaro”将推动开源软件新一波开发潮
查看>>
VS201“.NET研究”0实践RUP4+1架构模型
查看>>
两级导航栏联动效果
查看>>
php ftp类
查看>>
VK Cup 2012 Qualification Round 1 A. Next Round
查看>>
(译)cocos2d精灵教程:第二部分
查看>>
高校女生坐等强女干。保安称压力大。。【转】
查看>>
Python 版 Instance Activator
查看>>
分享30套免费的高质量网页按钮素材
查看>>
亲测SQLServer的最大连接数 (转)
查看>>
typeof 运算符用法
查看>>
SignalR 0.5 发布了
查看>>
批量照片缩小器展示多线程控件BackgroundWorker后台工作使用方法
查看>>
HTML5之Canvas绘图——Canvas画布调整之移动、缩放、旋转
查看>>
排查数据库性能的常用sql语句
查看>>
全排列
查看>>
Node.js&NPM的安装与配置(转)
查看>>