spring-boot 之 helloword

初识 spring-boot

  1. 参考文档

    spring-boot官方文档

  2. 示例环境

    • jdk 1.8
    • spring-boot 2.0.0
    • idea2015
    • OS: Windows10
  3. 新建一个Maven Java 工程

    • spring-boot 之 helloword_第1张图片

    • spring-boot 之 helloword_第2张图片

    • spring-boot 之 helloword_第3张图片

    • spring-boot 之 helloword_第4张图片

  4. 向pom.xml添加Spring Boot Maven依赖

    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0modelVersion>
    
        <groupId>com.examplegroupId>
        <artifactId>myprojectartifactId>
        <version>0.0.1-SNAPSHOTversion>
    
        
        <parent>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-parentartifactId>
            <version>2.0.0.BUILD-SNAPSHOTversion>
        parent>
    
        
        <dependencies>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-webartifactId>
            dependency>
        dependencies>
    
        
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-maven-pluginartifactId>
                plugin>
            plugins>
        build>
    
        
        
        <repositories>
            <repository>
                <id>spring-snapshotsid>
                <url>http://repo.spring.io/snapshoturl>
                <snapshots><enabled>trueenabled>snapshots>
            repository>
            <repository>
                <id>spring-milestonesid>
                <url>http://repo.spring.io/milestoneurl>
            repository>
        repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>spring-snapshotsid>
                <url>http://repo.spring.io/snapshoturl>
            pluginRepository>
            <pluginRepository>
                <id>spring-milestonesid>
                <url>http://repo.spring.io/milestoneurl>
            pluginRepository>
        pluginRepositories>
    project>
  5. 编写启动类

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @EnableAutoConfiguration
    public class Example {
    
        @RequestMapping("/")
        String home() {
            return "Hello World!";
        }
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Example.class, args);
        }
    
    }
  6. 运行程序

    • 在idea运行程

      spring-boot 之 helloword_第5张图片

    • 正常启动

      spring-boot 之 helloword_第6张图片

    • 测试

      spring-boot 之 helloword_第7张图片

你可能感兴趣的:(web,java,java,web,springboot)