Myeclipse下使用Maven搭建spring boot2.0项目
现在需要搭建spring boot框架,并实现一个HelloWorld的项目,让程序真正运行起来。
一、在pom.xml中引入spring-boot-start-parent,spring官方的叫stater poms,它可以提供dependency management,也就是依赖管理,引入以后在声明其它dependency的时候就不需要version了。
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.0.RELEASE</version>
- </parent>
二、需要在pom.xml中引入spring-boot-starter-web,spring官方解释spring-boot-start-web包含了spring webmvc和tomcat等web开发的特性。
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- </dependencies>
三、如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven的spring-boot:run的话就不需要此配置。
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
四、下面开始写程序,我们需要一个启动类,然后在启动类声明让spring boot自动给我们配置spring需要的配置,比如:@SpringBootApplication,为了可以尽快让程序跑起来,我们简单写一个通过浏览器访问hello world字样的例子:
- package hello;
- import org.springframework.boot.*;
- import org.springframework.boot.autoconfigure.*;
- import org.springframework.stereotype.*;
- import org.springframework.web.bind.annotation.*;
- @Controller
- @EnableAutoConfiguration
- public class SampleController {
- @RequestMapping("/home")
- @ResponseBody
- String home() {
- return "Hello World!";
- }
- public static void main(String[] args) throws Exception {
- SpringApplication.run(SampleController.class, args);
- }
- }
其中@EnableAutoConfiguration声明让spring boot自动给程序进行必要的配置,等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan。
@RestController返回json字符串的数据,直接可以编写RESTFul的接口。
五、运行我们的Application,特别简单:右键Run As -> Java Application。之后打开浏览器输入地址:http://127.0.0.1:8080/home 就可以看到Hello world!了。
六、完整的pom.xml文件
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.zst</groupId>
- <artifactId>mymaven</artifactId>
- <packaging>war</packaging>
- <version>0.0.1-SNAPSHOT</version>
- <name>mymaven Maven Webapp</name>
- <url>http://maven.apache.org</url>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.0.RELEASE</version>
- </parent>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- </dependencies>
- <build>
- <finalName>mymaven</finalName>
- </build>
- </project>
至些,我们的Spring boot项目已经搭建完成,并成功的运行了HelloWorld的项目。
借鉴:http://blog.csdn.net/a78270528/article/details/77573818
Myeclipse下使用Maven搭建spring boot2.0项目的更多相关文章
- Myeclipse下使用Maven搭建spring boot项目
开发环境:Myeclipse2017.JDK1.6.Tomcat 8.0.Myeclipse下使用Maven搭建spring boot项目,详细过程如下: 1. New -> Project.. ...
- 快速搭建spring boot2.0 项目
快速搭建spring boot2.0+mybatis+thymeleaf 项目 使用工具STS 3.9.7(eclipse) 首先创建一个spring boot2.0项目(具体创建方法就不写了) 然后 ...
- Myeclipse下使用Maven搭建spring boot项目(第二篇)
现在需要搭建spring boot框架,并实现一个HelloWorld的项目,让程序真正运行起来. 一.在pom.xml中引入spring-boot-start-parent,spring官方的叫st ...
- Maven搭建Spring Security3.2项目详解
本来是打算在上一篇SpringMVC+Hibernate上写的,结果发现上面那篇 一起整合的,结果发现上一篇内容实在是太长了,就另起一篇,这篇主要是采用 Maven搭建Spring+SpringMVC ...
- IDEA中maven搭建Spring+SpringMVC+mybatis项目
一.介绍 使用IDEA搭建maven web项目,整合框架Spring+SpringMVC+mybatis 项目结构图:
- Maven搭建Spring+Struts2+Hibernate项目详解
http://www.bubuko.com/infodetail-648898.html
- 【spring colud】spring cloud微服务项目搭建【spring boot2.0】
spring cloud微服务项目搭建 =================================== 示例版本: 1.spring boot 2.0版本 2.开发工具 IntellJ IDE ...
- spring boot2.0(一 ) 基础环境搭建
1.基础配置 开发环境:window jdk版本:1.8(spring boot2.0最低要求1.8) 开发工具:eclipse 构建方式:maven3 2.POM配置文件 <project x ...
- Spring Boot2.0使用Spring Security
一.Spring Secutity简介 Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性 ...
随机推荐
- python中常用内置函数用法总结
强制类型转换:int()float()str()list()tuple()set()dict()总结,这几种类型转换函数得用法基本一致,基本就是int(要转换得数据).返回值类型为对应得数据类型 ...
- js中forEach,for in,for of循环的用法
from:https://www.cnblogs.com/amujoe/p/8875053.html 一.一般的遍历数组的方法: var array = [1,2,3,4,5,6,7]; for (v ...
- 用 Flask 来写个轻博客 (30) — 使用 Flask-Admin 增强文章管理功能
Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 实现文章管理功能 实现效果 前文列表 用 Flask 来写个 ...
- Linux中zip压缩和解压缩命令
主要参数 -c:将解压缩的结果-l:显示压缩文件内所包含的文件-p:与-c参数类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换-t:检查压缩文件是否正确-u:与-f参数类似,但是除了更新现有的 ...
- 路由参数 query和params
1. path:'www.baidu.com' query { id:122 } 对应地址:http:'www.baidu.coom?id=122' 类似get方式 2.name:'baidu' ...
- 基于vue2.0打造移动商城页面实践 vue实现商城购物车功能 基于Vue、Vuex、Vue-router实现的购物商城(原生切换动画)效果
基于vue2.0打造移动商城页面实践 地址:https://www.jianshu.com/p/2129bc4d40e9 vue实现商城购物车功能 地址:http://www.jb51.net/art ...
- 【怒转】 idea快捷键说明大全(中英文对照)
1 编辑[Editing] 快捷键 英文说明 中文说明 Ctrl + Space Basic code completion (the name of any class, method or var ...
- Python里面search()和match()的区别?
match()函数只检测RE是不是在string的开始位置匹配,search()会扫描整个string查找匹配, 也就是说match()只有在0位置匹配成功的话才有返回,如果不是开始位置匹配成功的话, ...
- 修改默认runlevel
CentOS直接修改文件 /etc/inittab 就好了 # Default runlevel. The runlevels used are: # - halt (Do NOT set init ...
- Centos7 安装vscode
1.官网下载vscode https://vscode.cdn.azure.cn/stable/0f3794b38477eea13fb47fbe15a42798e6129338/code-1.36.0 ...