SpringBoot入门之HelloWorld
2016-11-29 23:08
429 查看
Alan Liu 接触SpringBoot 也是最近几个月,为了帮助有一定基础的码友们在学习SpringBoot时的入门实例。特此一系列整理下基于SpringBoot的学习知识,使我们共同学习进步;有不足之处望大家积极反馈,Thanks!
关键点在代码中注释的就不再重复叙述了哈。
大家对以上不熟悉的请先在网上找下相关资料学习下。
SpringBoot 构建依赖包管理两种方式:
其一:继承
其二:导入
3.2 程序启动类
@ComponentScan:开启注解扫描
@EnableAutoConfiguration:开启自动配置
3.3 HelloWorld类
啊哈,SpringBoot 的HelloWorld程序已完成。
关键点在代码中注释的就不再重复叙述了哈。
1.环境搭建
本系列开发环境:开发语言:java(jdk1.8); 发工具 IntelliJ IDE; 构建工具:Apache-Maven-3.1.0; 版本控制:Git; 代码托管平台:GitHub。
大家对以上不熟悉的请先在网上找下相关资料学习下。
2.新建工程
基于Maven构建工程venus-spring-boot。项目结构如图:3.SpringBoot 入门之HelloWorld
3.1 pom.xml文件SpringBoot 构建依赖包管理两种方式:
其一:继承
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.2.RELEASE</version> </parent> <dependencies> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ... </dependencies>
其二:导入
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.1.9.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
3.2 程序启动类
/** * Spring Boot入门之Hello World * @author Alan Liu * @create 2016-11-25 * 1.当工程中有@Component, @Service, @Repository, @Controller等,自动注册Spring Beans 需要添加 @ComponentScan * 2.@SpringBootApplication same as @Configuration @EnableAutoConfiguration @ComponentScan */ @ComponentScan @EnableAutoConfiguration public class AppVenus { public static void main( String[] args ) { SpringApplication.run(AppVenus.class,args); } }
@ComponentScan:开启注解扫描
@EnableAutoConfiguration:开启自动配置
3.3 HelloWorld类
/** * Controller * * @author Alan Liu * @create 2016-11-25 13:47 **/ @Controller public class HelloWorld { @RequestMapping("/helloworld") @ResponseBody public String helloWorld(){ return "Hello World!"; } }
4.SpringBoot项目启动
运行AppVenus.main方法,启动在控制台可以看到服务端口默认8080,默认应用服务器Tomcat.5.运行观察HelloWorld
在浏览器中输入http://localhost:8080/helloworld啊哈,SpringBoot 的HelloWorld程序已完成。
相关文章推荐
- springboot入门第二篇之Helloworld
- SpringBoot 入门:环境搭建与HelloWorld~
- springboot入门helloworld
- ActiveMQ 入门helloworld
- SpringBoot入门系列:Spring Security 和 Angular JS(1)
- 《SpringBoot学习-入门》
- Eclipse安装springsource-tool-suite插件及spring helloworld入门实例
- springBoot简单入门
- [Android]Android开发入门之HelloWorld
- SpringBoot入门-快速设置拦截器并实现权限验证
- SpringBoot 快速入门
- dubbo简单入门(helloworld例子)
- Angular 4入门教程系列:1:HelloWorld
- springboot 开发入门,及问题汇总
- Spring 入门之 HelloWorld 教程
- Android入门(1) 不一样的HelloWorld
- Node.js 极简入门Helloworld版服务器例子
- .Net 转战 Android 4.4 日常笔记(2)--HelloWorld入门程序
- Velocity 入门之 HelloWorld
- Drools入门-----------环境搭建,分析Helloworld