现在需要搭建spring boot框架,并实现一个HelloWorld的项目,让程序真正运行起来。

一、在pom.xml中引入spring-boot-start-parent,spring官方的叫stater poms,它可以提供dependency management,也就是依赖管理,引入以后在声明其它dependency的时候就不需要version了。

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. </parent>

二、需要在pom.xml中引入spring-boot-starter-web,spring官方解释spring-boot-start-web包含了spring webmvc和tomcat等web开发的特性。

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. </dependencies>

三、如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven的spring-boot:run的话就不需要此配置。

  1. <plugins>
  2. <plugin>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-maven-plugin</artifactId>
  5. </plugin>
  6. </plugins>

四、下面开始写程序,我们需要一个启动类,然后在启动类声明让spring boot自动给我们配置spring需要的配置,比如:@SpringBootApplication,为了可以尽快让程序跑起来,我们简单写一个通过浏览器访问hello world字样的例子:

  1. package hello;
  2.  
  3. import org.springframework.boot.*;
  4. import org.springframework.boot.autoconfigure.*;
  5. import org.springframework.stereotype.*;
  6. import org.springframework.web.bind.annotation.*;
  7.  
  8. @Controller
  9. @EnableAutoConfiguration
  10. public class SampleController {
  11.  
  12. @RequestMapping("/home")
  13. @ResponseBody
  14. String home() {
  15. return "Hello World!";
  16. }
  17.  
  18. public static void main(String[] args) throws Exception {
  19. SpringApplication.run(SampleController.class, args);
  20. }
  21. }

其中@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文件

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.zst</groupId>
  5. <artifactId>mymaven</artifactId>
  6. <packaging>war</packaging>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <name>mymaven Maven Webapp</name>
  9. <url>http://maven.apache.org</url>
  10. <parent>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-parent</artifactId>
  13. <version>2.0.0.RELEASE</version>
  14. </parent>
  15. <dependencies>
  16. <dependency>
  17. <groupId>junit</groupId>
  18. <artifactId>junit</artifactId>
  19. <version>3.8.1</version>
  20. <scope>test</scope>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.springframework.boot</groupId>
  24. <artifactId>spring-boot-starter-web</artifactId>
  25. </dependency>
  26. </dependencies>
  27. <build>
  28. <finalName>mymaven</finalName>
  29. </build>
  30. </project>

至些,我们的Spring boot项目已经搭建完成,并成功的运行了HelloWorld的项目。

借鉴:http://blog.csdn.net/a78270528/article/details/77573818

Myeclipse下使用Maven搭建spring boot2.0项目的更多相关文章

  1. Myeclipse下使用Maven搭建spring boot项目

    开发环境:Myeclipse2017.JDK1.6.Tomcat 8.0.Myeclipse下使用Maven搭建spring boot项目,详细过程如下: 1. New -> Project.. ...

  2. 快速搭建spring boot2.0 项目

    快速搭建spring boot2.0+mybatis+thymeleaf 项目 使用工具STS 3.9.7(eclipse) 首先创建一个spring boot2.0项目(具体创建方法就不写了) 然后 ...

  3. Myeclipse下使用Maven搭建spring boot项目(第二篇)

    现在需要搭建spring boot框架,并实现一个HelloWorld的项目,让程序真正运行起来. 一.在pom.xml中引入spring-boot-start-parent,spring官方的叫st ...

  4. Maven搭建Spring Security3.2项目详解

    本来是打算在上一篇SpringMVC+Hibernate上写的,结果发现上面那篇 一起整合的,结果发现上一篇内容实在是太长了,就另起一篇,这篇主要是采用 Maven搭建Spring+SpringMVC ...

  5. IDEA中maven搭建Spring+SpringMVC+mybatis项目

    一.介绍 使用IDEA搭建maven web项目,整合框架Spring+SpringMVC+mybatis 项目结构图:

  6. Maven搭建Spring+Struts2+Hibernate项目详解

    http://www.bubuko.com/infodetail-648898.html

  7. 【spring colud】spring cloud微服务项目搭建【spring boot2.0】

    spring cloud微服务项目搭建 =================================== 示例版本: 1.spring boot 2.0版本 2.开发工具 IntellJ IDE ...

  8. spring boot2.0(一 ) 基础环境搭建

    1.基础配置 开发环境:window jdk版本:1.8(spring boot2.0最低要求1.8) 开发工具:eclipse 构建方式:maven3 2.POM配置文件 <project x ...

  9. Spring Boot2.0使用Spring Security

     一.Spring Secutity简介     Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性 ...

随机推荐

  1. python中常用内置函数用法总结

    强制类型转换:int()float()str()list()tuple()set()dict()总结,这几种类型转换函数得用法基本一致,基本就是int(要转换得数据).返回值类型为对应得数据类型   ...

  2. 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 ...

  3. 用 Flask 来写个轻博客 (30) — 使用 Flask-Admin 增强文章管理功能

    Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 实现文章管理功能 实现效果 前文列表 用 Flask 来写个 ...

  4. Linux中zip压缩和解压缩命令

    主要参数 -c:将解压缩的结果-l:显示压缩文件内所包含的文件-p:与-c参数类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换-t:检查压缩文件是否正确-u:与-f参数类似,但是除了更新现有的 ...

  5. 路由参数 query和params

    1. path:'www.baidu.com' query  { id:122 } 对应地址:http:'www.baidu.coom?id=122'   类似get方式 2.name:'baidu' ...

  6. 基于vue2.0打造移动商城页面实践 vue实现商城购物车功能 基于Vue、Vuex、Vue-router实现的购物商城(原生切换动画)效果

    基于vue2.0打造移动商城页面实践 地址:https://www.jianshu.com/p/2129bc4d40e9 vue实现商城购物车功能 地址:http://www.jb51.net/art ...

  7. 【怒转】 idea快捷键说明大全(中英文对照)

    1 编辑[Editing] 快捷键 英文说明 中文说明 Ctrl + Space Basic code completion (the name of any class, method or var ...

  8. Python里面search()和match()的区别?

    match()函数只检测RE是不是在string的开始位置匹配,search()会扫描整个string查找匹配, 也就是说match()只有在0位置匹配成功的话才有返回,如果不是开始位置匹配成功的话, ...

  9. 修改默认runlevel

    CentOS直接修改文件  /etc/inittab 就好了 # Default runlevel. The runlevels used are: # - halt (Do NOT set init ...

  10. Centos7 安装vscode

    1.官网下载vscode https://vscode.cdn.azure.cn/stable/0f3794b38477eea13fb47fbe15a42798e6129338/code-1.36.0 ...