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

spring boot 入门 1

2016-10-25 10:18 302 查看
1,新建一个maven 工程。

2, 在pom.xml中加入依赖关系:

1) 加入parent的关系,让它程序自动下载到所有spring boot要用的主要jar文件。

    <parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>1.3.3.RELEASE</version>

  </parent>

2)加入web相关的开发包

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

3)简单的代码:

package com;

@RestController

@SpringBootApplication

public class App {

  

  @RequestMapping("/")

  public String hello(){

    return "Hello world!";

  }

  

  public static void main(String[] args) {

    SpringApplication.run(App.class, args);

  }

}

其中@SpringBootApplication申明让spring
boot自动给程序进行必要的配置,等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan
@RestController返回json字符串的数据,直接可以编写RESTFul的接口;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring boot