SpringBoot快速搭建笔记

来源:互联网 发布:mac os 10.7 iso下载 编辑:程序博客网 时间:2024/06/04 17:57

SpringBoot快速搭建

1.创建maven项目

2.配置pmo文件,文件内容如下:

<dependencyManagement>    <dependencies>        <dependency>            <!-- Import dependency management from Spring Boot -->            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-dependencies</artifactId>            <version>1.5.1.RELEASE</version>            <type>pom</type>            <scope>import</scope>        </dependency>    </dependencies></dependencyManagement>     <!-- Add typical dependencies for a web application -->  <dependencies>      <dependency>          <groupId>org.springframework.boot</groupId>          <artifactId>spring-boot-starter-web</artifactId>      </dependency></dependencies>    <!-- springboot 编译插件 -->  <build>      <plugins>          <plugin>              <groupId>org.springframework.boot</groupId>              <artifactId>spring-boot-maven-plugin</artifactId>          </plugin>      </plugins>  </build>

注:使用dependencyManagement而不是用 parent是因为我的项目是maven模块管理。

3.创建引导入口类。

package com.lcl.springBoot;@SpringBootApplication@ComponentScan(basePackages={"com.lcl.springBoot"})public class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }}

注:@SpringBootApplication等价于@Configuration、@EnableAutoConfiguration、@ComponentScan

4.创建控制层类。

package com.lcl.springBoot.controller;@RestControllerpublic class DemoController {    @RequestMapping("index")    public String index(){        return "hello,springBoot!";         }}

注:包名引导入口类报名对应。SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描。“Application类”是指SpringBoot项目入口类。引:http://blog.csdn.net/u014695188/article/details/52263903

5.运行Application类,以java Application方式运行。

6.在浏览器输入:http://localhost:8080/index。显示:hello,springBoot!

0 0
原创粉丝点击