springboot 学习笔记(一)
来源:互联网 发布:淘宝联盟认证 编辑:程序博客网 时间:2024/06/05 10:28
引子
最近在搞一个项目,走在科技前沿的师兄, 摒弃了公司老套的框架模式, 采用了springboot搭建新应用。看到如此简洁的代码 , 深受诱惑。趁周末闲余之时, 背晒阳光, 学起了springboot, 记学习之感。
我们来电 简单粗暴, 搭建个应用run起来 . 本文不介绍细节, 后续会深入了解springboot, 剖析源码, 敬请关注。
一、搭建一个maven模块工程(具体可以参考我另一篇博文 《命令行创建maven模块工程》)
1、父工程
mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo -DarchetypeArtifactId=maven-archetype-site-simple -DinteractiveMode=false2、子工程client端mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo-client -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false3、子工程server端mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
二、springboot的引入
添加springboot 的父pom配置
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.0.RELEASE</version> </parent>
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.3.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
要添加springboot构建的web 子工程, pom只需配置
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>
pom加入这些配置后, 可以自动依赖内嵌的tomcat 和 spring-mvc了 , 从而支持了web开发
三、定义springboot的主类(启动tomcat)
@RestController@EnableAutoConfigurationpublic class Application { @RequestMapping("/") public String index() { return "hello, spring boot"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
@EnableAutoConfiguration : 表明了这个类是springboot的主类。
可以看到启动入口就是main函数了。赶紧跑下看看, 可以访问 http://localhost:8080/
可以看到页面输入
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Courier New"; color: #3933ff }hello, spring boot
截止到这里,我们就完成了一个简单的springboot工程搭建。后期会计划深入了解, 敬请mark
四、参考文献
springboot官方文档
0 0
- springboot 学习笔记(一)
- springboot 学习笔记(一)
- springboot 学习笔记(一)
- springboot学习笔记(一)
- SpringBoot学习笔记(一)
- SpringBoot学习笔记一
- springboot学习笔记一
- Springboot学习笔记(一)
- SpringBoot学习笔记(一)
- SpringBoot 学习笔记一
- springboot学习笔记(一) HelloWorld
- springboot笔记(一)
- springBoot 学习(一)
- springboot学习(一)
- SpringBoot学习(一)
- SpringBoot学习(一)SpringBoot基础入门
- (小白学习笔记)Springboot入门(一):Specification
- Spring Boot 学习笔记一(SpringBoot启动过程)
- Manacher(hdu3068最长回文)
- redis服务启动
- 洛谷1381 单词背诵
- mac 安装MySQL
- 洛谷1026 统计单词个数
- springboot 学习笔记(一)
- springboot 学习笔记(二)--- properties 配置
- 2017.2.10测试 藏妹子之处
- linux下rsync命令详细整理
- fastJson泛型如何转换
- python-网络爬虫初学一:获取网页源码以及发送POST和GET请求
- codevs 3342绿色通道
- mac 开发必备软件(不断update ing...)
- 可爱的猴子