zoukankan      html  css  js  c++  java
  • Eclipse搭建SpringBoot

    第一种方法(不建议)

    首先新建Maven工程

     勾选第一个按钮,第三个是选择working set ,你可以不选

    下一步,配置工程信息,注意打包为jar

     

     打开pom.xml文件,添加spring-boot依赖

    复制代码
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.9.RELEASE</version>
        </parent>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    复制代码

     新建文件src/main/hello/HelloController.java

    复制代码
    package hello;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class HelloController {
    
        @RequestMapping("/")
        public String hello(){
            return "Greetings from Spring Boot!";
        }
    }
    复制代码

    新建src/main/hello/Application.java

    复制代码
    package hello;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            // http://localhost:8080/
            SpringApplication.run(Application.class, args);
        }
    }
    复制代码

    运行Application

    出现一堆:

    访问localhost:8080/

     

     第二种方法(推荐)

    1. 打开eclipse,选择Help--Eclise Marketplace

    2. 2

      打开"Popular"标签,可以看到STS,直接安装

      这种事在线安装,必须这联网的,想要离线安装的要下载安装包

    3. 3

      然后我们新建工程就可以看到springboot

    File-》new-》other

     选择starter项目

     下一步

     下一步

     勾选Web,Finish。可以看到项目结构与我们自己建的Maven有些不一样。

    新建一个Controller

    复制代码
    package com.example.demo;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class HelloController {
    
        @RequestMapping("/")
        public String hello(){
            return "Welcome to start SpringBoot!";
        }
    }
    复制代码

    运行

     

     运行结果

     

     比起原来的Spring项目,构建过程简单多了

  • 相关阅读:
    用grunt搭建自动化的web前端开发环境-完整教程
    SQL Server:触发器详解
    利用junit对springMVC的Controller进行测试
    jquery-barcode:js实现的条码打印
    16个良好的 Bootstrap Angularjs 管理后台主题
    Spring Security 4 Hello World Annotation+XML
    intellij 13新建javaweb项目并用tomcat 7启动
    JavaScript类和继承:constructor属性
    javascript 的面相对象
    javascript call apply bind caller callee 的用法
  • 原文地址:https://www.cnblogs.com/gaobing1252/p/8558633.html
Copyright © 2011-2022 走看看