SpringBoot的学习【1.初学之HelloWorld】

1.创建Maven项目。

2.引入pom依赖

在springboot官网中找到简单的依赖模板

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

3.写启动程序

 
 
/**
* @SpringBootApplication用来标注此项目为springboot的注解
*/
@SpringBootApplication
public class First {
    public static void main(String[] args) {
        //Spring应用启动起来
        SpringApplication.run(First.class,args);

    }
}

4.Controller

@Controller
public class FirstController {
    @ResponseBody
    @RequestMapping("/hello")
    public String hello() {
        return "hello world";
    }
}

5.运行

直接运行启动,不需要配置tomcat等。就可以启动并访问项目

6.添加插件

 <!--打包成可执行的jar包 -->
    <build>
        <plugins>
            <plugin>
                <groupId> org.springframework.boot </groupId>
                <artifactId> spring-boot-maven-plugin </artifactId>
            </plugin >
        </plugins>
    </build>

不添加此插件,打包成的jar包无法执行。(maven插件的backage就可以打包)。

猜你喜欢

转载自www.cnblogs.com/miaoww/p/9235074.html
今日推荐