Java 从0到1搭建maven项目配置springboot并运行

此系列文章第二篇地址

一、准备工作
1.下载安装eclipse
2.下载tomcat,配置到eclipse
3.下载maven, 配置到eclipse

二、创建maven项目
1.打开Eclipse,点击File->New->Other,在弹出对话框中,选中Maven Project。(如下图)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2.编写pom.xml,添加springboot依赖(见下方代码,添加后保存)
更新项目依赖:右键项目选择Maven->Update Project(如项目无报错,则不需要)

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>
	<!-- 继承父包 -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.0.RELEASE</version>
	</parent>

3.调整编译环境,在项目上右键选择properties,然后点击java build path,在Librarys下,编辑JRE System Library,选择workspace default jre就可以了。(如下图)
在这里插入图片描述
4.在src/mian/java下创建class文件,TestApplicariontion.class内容如下:

package com.liu.demo20190304;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class TestApplicariontion{

	@RequestMapping("/")
	String home() {
		return "hello word!";
	}

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

5 测试,右键点击TestApplicariontion → run as javaApplication/run on Server,亲测,都可以运行,运行效果如下:
打开:http://localhost:8088/,端口8088是我配置的tomcat端口,
效果:页面中仅显示hello word

此系列文件第二篇连接

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值