标签:
1. 安装maven:
1)下载maven软件包
2)解压软件包
3)添加环境变量MAVEN_HOME=maven解压后的路径
4)在环境变量Path后面添加;%MAVEN_HOME\bin%;
5)在cmd中运行mvn -v查看maven是否安装成功
2.在eclipse中创建一个maven工程:
New->Other->maven->Maven Project
3.编辑pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>org.springframework</groupId>
<artifactId>gs-scheduling-tasks</artifactId>
<version>0.1.0</version>
<!--
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>1.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4.保存pom.xml
5.编辑主函数所在java文件如下:
package com.lenovo;
/**
* Hello world!
*/
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class App {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
}
@RequestMapping(value = "/test", method = RequestMethod.GET)
@ResponseBody
public static String HelloWorld(){
return "Hello World";
}
}
6.编译运行程序
在浏览器中输入:http://127.0.0.1:8080/test回车,在浏览器中出现"Hello World"字样
maven配置spring boot
标签:
原文地址:http://www.cnblogs.com/candycloud/p/4439894.html