Spring Boot (一) 最简单跑起Hello World!
来源:互联网 发布:js切换隐藏 编辑:程序博客网 时间:2024/05/22 09:38
Spring Boot (一)
注:本例子是spring Boot 框架的Web项目开发
运行环境
- windows 10
- eclipse
- jdk 1.8
- maven 3.5.0
1. 首先新建一个Maven工程,这里我就省略了,可参考
http://blog.csdn.net/yioow/article/details/78614600
2. pom.xml导入jar包
官方文档实例,都让我们继承spring-boot-starter-parent
原文:To configure your project to inherit from the spring-boot-starter-parent set the parent
spring-boot-starter-web是web开发用的
<!-- Inherit defaults from Spring Boot (Spring boot 父引用) --><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version></parent><!-- Add typical dependencies for a web application (Spring boot 核心web) --><dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency></dependencies>
注:如果再导包过程中项目报错,可以项目右键-> 点击Maven-> 点击Update Project 即可
附:还可以加入这段配置(加不加都可以,看自己需要)
Spring Boot包含一个Maven插件,可以将项目打包为可执行的jar文件,还有一个是Spring Boot 的jdk插件,可以规定jdk版本。
<build> <plugins> <!-- Package as an executable jar/war --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- jdk编译插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <!-- 源代码使用的开发版本 --> <target>1.8</target> <!-- 需要生成的目标class文件的编译版本 --> </configuration> </plugin> </plugins></build>
3.新建一个包,包内有一个Application.java,负责启动程序
com +- test +- springBoot +- Application.java
Application.java 的内容如下
package com.test.springBoot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.support.SpringBootServletInitializer;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@SpringBootApplication@Controllerpublic class Application extends SpringBootServletInitializer{ @RequestMapping("/") @ResponseBody public String index() { return "Hello World!"; } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
生成可部署的war文件的第一步是提供一个 SpringBootServletInitializer子类并重写它的configure方法。这样做可以利用Spring框架的Servlet 3.0支持,并且可以让你的应用程序在被servlet容器启动的时候进行配置。通常,程序的主类以继承SpringBootServletInitializer
4.启动程序 Application.java文件右键-> 点击Run As-> 点击Java Application 即可
5.在浏览器输入http://localhost:8080/
Good Luck!
附:
代码
http://download.csdn.net/download/yioow/10131127?locationNum=1&fps=1
SpringBoot 使用文档
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven
阅读全文
0 0
- Spring Boot (一) 最简单跑起Hello World!
- Spring Boot:简单Hello World
- Spring boot (一) Hello World
- spring boot(1)-简单搭建 Hello World
- Spring-Boot学习笔记一:Hello World
- Spring Boot学习一Hello World!
- Spring Boot实践教程(一):Hello,world!
- Spring boot之hello world(一)
- spring-boot-hello-world
- spring-boot Hello World
- hello World Spring Boot
- Spring-boot搭建一个简单的Hello World工程
- spring boot 利用分层结构输出简单的Hello world
- Eclipse使用maven搭建简单spring boot application Hello World
- Spring Boot学习笔记-从Hello World开始 (一)
- spring boot 入门(一):IntelliJ IDEA 实现hello world
- Spring Boot学习入门篇(一)--Hello World
- Spring Boot学习之旅:(一)HELLO WORLD
- Replugin startActivity流程
- 【ES系列二】——head可视化工具安装
- C++ 数组名与指针的区别
- Hive学习之Metastore及其配置管理
- 使用DB2报错:ERROR [42818] [IBM][DB2/NT] SQL0401N The data types of the operands for the operation "=" a
- Spring Boot (一) 最简单跑起Hello World!
- 并发编程工具之一:CountDownLatch 用法
- 给PLSQL插上飞翔的翅膀-PLSQL优化
- log4j.xml配置
- Error creating bean with name 'redisTemplate' defined in file
- MorphDynaBean 对象转换具体的实体POJO对象
- jvm 开始压缩指针
- 数据安全加密技术分析
- oracle中sql语句查询优化(三)