spring-boot 初学一

来源:互联网 发布:斗地主服务端源码 编辑:程序博客网 时间:2024/04/29 00:42

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/

0 0
原创粉丝点击