码迷,mamicode.com
首页 > 编程语言 > 详细

maven配置spring boot

时间:2015-04-19 21:21:18      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!