美文网首页
SpringBoot学习笔记

SpringBoot学习笔记

作者: jerrybw | 来源:发表于2017-07-13 12:54 被阅读0次

1.快速搭建一个springboot项目

首先创建一个一般的Maven项目,有一个pom.xml和基本的src/main/java结构。

在pom.xml中写上如下内容:

<?xml version="1.0" encoding="UTF-8"?>
<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.0</modelVersion>

    <groupId>com.github.abel533</groupId>
    <artifactId>spring-boot</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.0.RELEASE</version>
    </parent>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.5.RELEASE</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

在根包下创建一个应用类:

@RestController
@EnableAutoConfiguration
@ComponentScan
public class Application {

    @Autowired
    private Person person;
    
    @RequestMapping("/")
    String home() {
        String name = person.getName();
        return "Hello world" + name;
    }

    @RequestMapping("/now")
    String hehe() {
        return "现在时间:" + (new Date()).toLocaleString();
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

启动项目

在IDE中直接直接执行main方法,然后访问http://localhost:8080即可。

相关文章

网友评论

      本文标题:SpringBoot学习笔记

      本文链接:https://www.haomeiwen.com/subject/yoewhxtx.html