eclipse 使用maven 构建springboot 程序

1、创建Maven工程

打开Eclipse,点击File->New->Other,在弹出对话框中,选中Maven Project。 
这里写图片描述

点击Next按钮,出现下图,根据自己需要设置,可以使用默认的。 
这里写图片描述

再点击Next按钮,出现下图,选中图中背景为蓝色的项。 
这里写图片描述

再点击Next按钮,设置Group Id和Artifact Id,其他项可以不用设置。 
这里写图片描述

点击Finish按钮,完成项目的创建。

2、编写pom.xml

在parent部分使用spring-boost-starter-parent。spring-boost-starter-parent是重要的默认的父工程,它提供了dependency-management部分。

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.3.RELEASE</version>
</parent>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

如果我们向pom.xml添加spring-boot-starter-web依赖(在parent这部分之后):

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

此时pom.xml如下所示: 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.wlsq.accounts</groupId>
	<artifactId>WlsqAccounts</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.3.RELEASE</version>
	</parent>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>

3、测试Spring Boot 应用

在src/main/java目录下,新建一个com.zzg.apple包,然后在包下面新建一个类。

package com.wlsq.app;

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 AppleApplication {
  @RequestMapping("/")
     String home() {
         return "欢迎使用SpringBoot!";
     }
     public static void main(String[] args) {
         SpringApplication.run(AppleApplication.class, args);
     }
}

启动程序,右键AppleApplication.java文件,选择run as -> Java Application。  
如果没有报错的话,在浏览器中输入:  http://localhost:8080/  


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值