zoukankan      html  css  js  c++  java
  • 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”了。

  • 相关阅读:
    十、Compose命令
    九、compose入门
    JS数组中,两两比较的算法,为了获取重复的值,并在php数组中,使用这种倒三角算法
    题目重复度检测---四种相似度检测的方案+PHP改进计算字符串相似度的函数similar_text()、levenshtein()
    js让文字一个个出现
    客户总想让页面炫酷起来-----怎么炫酷呢?---使用css3的东西或者其animate.css
    关于git的总结:git知识大全,命令行操作,vscode操作
    defer和async的区别
    dom和bom的区别,以及三类偏移属性(JS运动方法中,经常会涉及到这些位置信息)
    认真的对待flex,Flex模型和Flex属性思维导图,以及自己的记忆方法--jaf和aof
  • 原文地址:https://www.cnblogs.com/CHENJIAO120/p/7079361.html
Copyright © 2011-2022 走看看