1.使用myeclipse搭建springboot

1) File -> New ->Other

SpringBoot学习(一)myeclipse搭建springboot

SpringBoot学习(一)myeclipse搭建springboot

SpringBoot学习(一)myeclipse搭建springboot

选Spring Web 是为了嵌入一个tomcat,会在pom.xml自动增加:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

2) 创建好的目录结构

SpringBoot学习(一)myeclipse搭建springboot

pom.xml报错了

SpringBoot学习(一)myeclipse搭建springboot

这是由于maven版本问题导致的,解决方法:

    <properties>
        <maven-jar-plugin.version>3.0.0</maven-jar-plugin.version>
    </properties>

SpringBoot学习(一)myeclipse搭建springboot

3) 更新项目,文章最后有换源的教程,下载jar包快

SpringBoot学习(一)myeclipse搭建springboot

现在项目没有报错了

4)SpringBootDemoApplication.java名太长了,我改短点,改成了Application.java,需要重新Update Project ,这步可以忽略

5)新建HelloController.java

package com.example.demo.controller;

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

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello() {

        return "Hello World!";
    }
}

6) 执行Application.java ,选Java Application 或者Spring Boot App运行都可以

SpringBoot学习(一)myeclipse搭建springboot

7)浏览器访问 http://localhost:8080/hello 

SpringBoot学习(一)myeclipse搭建springboot

8) maven换源 (可选)

Window -> Pregerences

SpringBoot学习(一)myeclipse搭建springboot

 在这个位置的settings.xml内容换成:(没有这个文件则创建,或者放到其他位置,点Browse选择也可以)

<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <mirror>
            <id>aliyun</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>
</settings>

相关文章:

  • 2021-05-14
  • 2021-04-30
  • 2021-10-29
  • 2021-04-08
  • 2021-04-11
  • 2021-06-27
  • 2021-10-15
  • 2021-09-01
猜你喜欢
  • 2021-07-15
  • 2021-09-15
  • 2021-10-07
  • 2021-04-09
  • 2021-09-06
  • 2021-09-24
  • 2021-11-29
相关资源
相似解决方案