您的位置:首页 > 编程语言 > Java开发

springboot入门

2016-07-27 15:43 435 查看
spring是我们最熟悉不过的框架,但是其各种xml文件配置过于繁琐复杂,很容易出错。
现在推广一个springboot框架,轻量级,方便。
步骤:(楼主用的lead2016)
1.建立一个maven项目
2.添加依赖,如下:
<?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>com.springboot</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<!--parent-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>


3.建一个java类  controller
package springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* Created by 28906 on 2016/7/27.
*/
@Controller
@EnableAutoConfiguration
public class springBootTest {

@RequestMapping("/hello")
@ResponseBody
public String sayHello(){
return "Hello springboot!";
}

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


4.直接run,输出如下:





然后打开浏览器直接输入http://localhost:8080/hello  结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: