• 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”了。

  • 相关阅读:
    无线网络安全标准是什么?漏洞是怎样产生的
    揭秘英特尔处理器如何启动?
    数据包级网络遥测和网络安全推送分析
    自动化与网络工程之间的关系
    ElementUI中的el-table中实现动态添加一行、删除一行、清空所有行
    ElementUI中的el-table实现多选框不勾选的提示
    Nodejs中的fs模块的使用
    ElementUI中的el-table怎样实现多选与单选
    MyBatis中针对if-test的参数为指定值的xml写法
    SqlServer中怎样从Excel中导入数据
  • 原文地址:https://www.cnblogs.com/CHENJIAO120/p/7079361.html
Copyright © 2020-2023  润新知