springboot开发环境搭建

姓名:陈中娇   班级:软件151

第一步:在Eclipse下面配置Maven环境

一、使用spring boot新建maven工程不在需要建立maven web工程,只要一般的maven工程就好了。 
二、maven包的导入 
清单如下:

<!-- Inherit defaults from Spring Boot -->
  <parent>
  <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.BUILD-SNAPSHOT</version>
  </parent>
 
<!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency
        <!-- spring data jpa -->
        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
 
<!-- mysql driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

以上为部分spring boot 构建简单web项目所需要的maven配置文件。 

第二步:构建Maven+spring web 项目 : 
1.打开Eclipse,选择新建Maven Project

2.然后利用向导分别建立一个webapp项目和quickStart项目

在新建的过程中会要设置要设置几个东西groupId = cn.springbooot artifactId =SpringBootFrist ,剩下的设置就用默认的就可以了。

3.然后是将 webapp项目下面的WebApp目录复制到quickstart项目之中,最后在在SpringBootFirst工程下面新建一个src/main/resources 目录来配合Maven的目录结构。这样最后形成的SpringBootFirst工程就已经基本实现了整体的框架。

Spring boot 实现简单的RestFul项目

第一步: pom.xml 配置文件的设置 

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

上面这个是实现Spring Boot中web服务最基本的配置,写在pom.xml中就可以了。

第二步:编写Java代码 

首先我将Spring Boot官方所给的代码例子贴在下面,以此说明,在Spring Boot的项目运行,部署和发布,我们需要的东西不是很多。

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("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }
    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    } }

将上述的代码放入SpringBootFirst工程的src/main/java目录下面,进行运行,再在浏览器中输入http://localhost:8080/ ,我们就能看到“Hello,World”了。

posted @ 2017-06-26 10:23  我心唯一  阅读(1756)  评论(0编辑  收藏  举报