springboot环境快速搭建

为了后面可视化配置,这里先配上MAVEN(https://maven.apache.org/download.cgi官网上windows最新zip版的比如:apache-maven-3.6.2-bin.zip

解压缩即可用,这里需要在eclipse里配置一下:

1.Windows->Preference->Maven->Installations:在User Settings里Browse刚才解压缩的根目录比如:x:\apache-maven-3.6.0\这个目录(这个目录里应该能看到bin、conf等目录),把勾打上。

2.修改Local Repository,在User setting中browse选择conf/setting.xml文件,然后点击蓝色的像超链接的open file,会在IDE中打开此文件

3.点击Source,找到文档里的这个注释
    <!-- localRepository | The path to the local repository maven will use to 
        store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> -->

打开注释改成自己的目录(可以是任意位置新建的文件夹)

4.(可选),改成国内公库镜像提高下载速度,一般是阿里的:

跟上面的修改方式一样,找到对应注释位置打开并改成以下内容:

        <mirror>
            <id>alimaven</id>
            <name>aliyunmaven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>

准备工作做完后下载IDE工具(https://spring.io/tools3/sts/legacy,选择一个版本),本例以32位的STS3.9.6(建议结合自己的环境下载64位最新版的,或其它JAVA EE开发工具)

1.解压缩即可用(默认已经安装好JDK1.8及以上),选择工作空间,在目录sts-bundle\sts-3.9.6.RELEASE\下双击STS即可

2.在Package Explorer中右键New->Spring Starter Project

3.以demo为例仅下一步进入Project Dependencies页面

4.这里可以选择要加载的JAR包,一般JDBC、MyBatis、Mysql、Spring Web Thymeleaf就够了,不全后期可以在POM.XML中加

5.下一步后应该可以编程了,这时候Pom.xml里有个红叉,想去掉的话在pom.xml里将

<properties>
        <java.version>1.8</java.version>
    </properties>

改成:

<properties>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
        <java.version>1.8</java.version>
    </properties>

然后右键工程名——>MAVEN——>Update Project即可

如果这时仅想跑通Controller,把@SpringBootApplication
public class DemoApplication {

改成:

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class DemoApplication {

再启动就不会报错了,如果以后需要配数据库还要去掉exclude= {DataSourceAutoConfiguration.class}

这时应该可以在浏览器访问自己写的Controller了

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";
    }
}
 

在浏览器中访问:

http://localhost:8080/hello

页面效果:

hello

发布了39 篇原创文章 · 获赞 38 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/FRESHET/article/details/100578969