Spring boot2.0 入门(一)-使用eclipse 创建Spring boot项目

1.下载maven并解压
http://maven.apache.org/
2.配置eclipse中要使用maven,将maven解压好的路径配置进来
Window->Preferences->Maven->Installations->add
在这里插入图片描述
3.配置要使用的maven的setting配置文件(在maven的conf目录下),local Repository本地仓库没有的话就默认就行
在这里插入图片描述
如果需要指定jdk版本需要在setting中添加

<profiles>
	<profile>    
    <id>jdk-1.8</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>   
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
	</profile>
</profiles>

4.在eclipse中新建maven工程
(1).new maven Project
(2).选择默认
在这里插入图片描述
(3).选择quickstart
在这里插入图片描述
(4)设置工程名
在这里插入图片描述
(5)工程创建成功
在这里插入图片描述
如果程序中不出现src/main/java,src/test/java等,需要为工程设置正确的jre(建议是选装好的jdk路径,因为spring boot打包成jar包需要jdk)
即右键工程->properties->java Build Path
在这里插入图片描述
5.在pom.xml中添加Spring boot依赖,更多spring boot使用手册可参考它的用户手册

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.0.3.RELEASE</version>
	<relativePath />
</parent>
<dependencies>
	<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
</dependencies>

6.创建hello world测试
(1)创建两文件,HelloSpringboot.java和MainApplication.java(主函数)
在这里插入图片描述

HelloSpringboot.java

package com.haha.SpringbootTest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloSpringboot {

	@RequestMapping("/hello")
	@ResponseBody
	public String hello()
	{
		return "hellow world";
	}
}

MainApplication.java

package com.haha.SpringbootTest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MainApplication {

	public static void main(String[] args) {
		
		SpringApplication.run(MainApplication.class, args);
	}
}

2.在MainApplication.java中运行工程,然后在浏览器输入http://localhost:8080/hello
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值