(1) 学习SpringBoot 之HelloWorld
来源:互联网 发布:阿莫源码 编辑:程序博客网 时间:2024/05/22 00:47
使用SpringBoot微服务框架,必须使用到Maven等项目管理工具
SpringBoot 特性
1.创建独立的Spring应用程序
3.自动装配Spring依赖包
1.创建一个Maven项目 quickstart类型
2.在pom.xml中添加SpringBoot依赖
<!-- 可以直接从Spring官网Demo拷贝 --><parent><!-- SpringBoot 父节点依赖,引入之后相关的依赖就不需要添加version配置 --><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.7.RELEASE</version></parent>
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
3.编写SpringBoot启动类
使用SpringBootApplication注解,需扫描到的控制器类必须在启动类所属包的子包之中
/* * SpringBootApplication是一个复合注解 * 可以代替 @EnableAutoConfiguration和@ComponentScan * 这两个注解 */@SpringBootApplicationpublic class StartSpringBootMain { public static void main( String[] args ) { /* * 启动入口 */ SpringApplication.run(StartSpringBootMain.class, args); }}
4.编写HelloController控制类
package cn.moye.springbootHelloWrold.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/* * @RestController这是一个复合注解 * 可以代替 @Controller和@ResponseBody */@RestControllerpublic class HelloController {@RequestMapping("/")public String Hello(){return "Hello World"; }}
5.运行测试
运行启动类,右键点击Run as --> JavaApplication
出现如下信息:表示运行成功。
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.7.RELEASE)
打开浏览器 输入localhost:8080 可以看到Hello World ,这样SpringBoot 之HelloWorld 就完成了。
阅读全文
0 0
- (1) 学习SpringBoot 之HelloWorld
- (1) 学习SpringBoot 之HelloWorld
- SpringBoot学习笔记--HelloWorld
- Springboot学习一 helloworld
- Springboot 之 Helloworld
- SpringBoot入门之HelloWorld
- 2.Springboot 之 Helloworld
- SpringBoot入门之HelloWorld
- springboot之helloworld
- SpringBoot之Helloworld
- SpringBoot(1)--------helloworld
- SpringBoot学习——SpringBoot入门HelloWorld
- springboot学习-基本配置helloworld
- springboot学习笔记(一) HelloWorld
- springboot helloworld 简洁之道
- SpringBoot入门系列之第一篇:HelloWorld
- 手把手教你写springboot之helloworld
- springboot入门第二篇之Helloworld
- Java配置path和classpath的含义详解
- 一个小demo
- 强推!8个可以提高办公效率的PPT技巧
- django常用库
- 朴素贝叶斯法
- (1) 学习SpringBoot 之HelloWorld
- 字节码加载和class实例(静态成员变量对象加载顺序)
- PixHawk学习笔记 之 目录
- Java集合框架源码分析(四)——LinkedHashMap
- PageHelper3.6.3问题
- 下拉框带搜索
- 字节长度与打印格式
- K-means算法进行简单的图像"语义"分割,java
- spring boot guava cache 缓存学习