1.前戏准备:

  

  SpringBoot核心jar包:这里直接从Spring官网下载了1.5.9版本.

  jdk:jdk1.8.0_45.

  maven项目管理工具:3.5版本.

  tomcat:8.5版本.

  本地仓库:注意settings.xml里面的设置"<localRepository>E:/SpringBoot/repository</localRepository>"红色部分代表仓库的位置.

  eclipse:jee-neon3版本.

2.环境设置

  1)将jdk以及maven的环境变量配置好,配好后在dos窗口进行测试:命令为java -version 和 mvn -v

  JAVA_HOME:jdk所在目录

  path:%JAVA_HOME%\bin

  clathpath:%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar

  MAVEN_HOME:maven所在目录

  path:%MAVEN_HOME%\bin

  2)eclipse设置

  jre替换成1.8版本:Windows-->Preferences-->java-->Installed JREs

  maven仓库及路径设置:Windows-->Preferences-->maven-->installations 新建一个maven

            :Windows-->Preferences-->maven-->user settings 路径都设为仓库的settings.xml所在路径

  server:Windows-->Preferences-->server-->RunTime Environments 添加tomcat8.5

3.创建简单的maven项目

  创建一个maven start项目

  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/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.sinosoft</groupId>

   <artifactId>HelloSpring</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>jar</packaging>

  <name>HelloSpring</name>

  <url>http://maven.apache.org</url>

  <properties>

  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

   </properties>

  <parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.5.9.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>

</project>

   在src/main/java下新建一个Controller类

  package com.sinosoft.HelloSpring;

   import java.io.IOException;

   import javax.servlet.http.HttpServletResponse;

   import org.springframework.boot.SpringApplication;

   import org.springframework.boot.autoconfigure.SpringBootApplication;

   import org.springframework.web.bind.annotation.RequestMapping;

   import org.springframework.web.bind.annotation.RestController;

 

   @RestController

   @SpringBootApplication

   public class HelloSpring {

@RequestMapping("/app")

void index(HttpServletResponse res) throws IOException{

res.getWriter().println("Hello World!");

}

public static void main(String[] args) {

SpringApplication.run(HelloSpring.class, args);

}

  }

 运行main方法,在浏览器中输入http://localhost:8080/app就能得到 Hello World! 的结果

4.浏览器差异可能导致的问题

  最开始用的IE8浏览器,代码及报错如下:

  @RestController

   @SpringBootApplication

   public class HelloSpring {

@RequestMapping("/app")

String index(){

   return "Hello World!";

}

public static void main(String[] args) {

SpringApplication.run(HelloSpring.class, args);

}

  }

  

  可是我在360浏览器上却可以正常运行并出结果,后来经查询资料,得到这是ie8不支持

 所以将红色部分方法替换为

  void index(HttpServletResponse res) throws IOException{

res.getWriter().println("Hello World!");

    }

  便可在ie8上完美运行

这只是个开始...

最新文章

  1. mysql-3 检索数据(1)
  2. PHP获取毫秒时间戳,利用microtime()函数
  3. ServletContext总结
  4. C语言中static变量详解
  5. sqlserver,sqlite,access数据库链接字符串
  6. 【原】使用ajax的get异常获取数据的时候,IE浏览器总是有缓存
  7. 连接Excel文件时,未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序
  8. Hibernate中的一对多关系详解(2)
  9. CDOJ UESTC 1220 The Battle of Guandu
  10. SDN第一次作业
  11. 011_python常用查询
  12. python0301
  13. Tensorflow学习资源
  14. mongodb笔记(二)
  15. DevExpress v18.1新版亮点——CodeRush for VS篇(一)
  16. Exp7 网络欺诈技术防范
  17. 根据ip地址获取用户所在地
  18. 使用zabbix发送邮件的简易设置流程(存档用)
  19. 2016-2017-20155329 《Java程序设计》第7周学习总结
  20. UESTC 1511(差分约束)

热门文章

  1. Future复习笔记
  2. Linux服务器---邮件服务openwebmail安装
  3. strace跟踪多进程与内核的交互
  4. 1069: 统计字符gets函数
  5. POSIX rename语义
  6. LNMP的并发配置和资源分配
  7. Twemproxy和Redis性能压力测试
  8. 几张图看明白VAO、VBO、EBO的关系和代码顺序
  9. ES6知识整理(3)--函数的扩展
  10. go 字符串反转(倒序)