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

spring-boot 初学一

2016-04-25 19:42 561 查看

spring boot 学习

由于工作原因开始使用spring-boot这个框架,spring-boot与spring比较之下能够非常快速的搭建项目并进行开发。下面是我开始简历的一个简单Demo:spring-boot-demo

1、创建maven项目,并修改pom.xml文件

`

2、在代码中新建Main执行的类 Application.java

`package com.hhp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

/**
 * Created by huanghaopeng on 16/4/25.
 */

@EnableAutoConfiguration
@ComponentScan(value = {“com.hhp”})
public class Application {
 public static void main(String[] args) throws Exception {
 SpringApplication.run(Application.class, args);
 }
}


3、新建自己的Controller

`package com.hhp.action;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by huanghaopeng on 16/4/25.
 */
@Controller
public class TestController {
 @RequestMapping(“/”)
 @ResponseBody
 String home() {
 return “HelloWord”;
 }
}

4、新建maven启动



5、启动tomcat(tomcat是spring-boot中自带的tomcat)

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