1.SpringBoot

1、工具下载

Eclipse:http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neonr
Spring Tool Suite:https://spring.io/tools/sts/all

2、Eclipse安装Spring Tool Suite

a、打开Help —> Install New Sofware…
b、Add…
c、Loccal…,选中解压之后的springsource-tool-suite,之后点击 OK
d、点击 Select All,之后确认,多次确认,提示重启eclipse时重启即可
可以选中在线安装Spring Tool Suite 这个插件。Help —> Eclipse Marketplace…之后搜索spring tool suite(其中Eclipse Marketplace在neonr版本上有)码片

3、创建第一个SpringBoot工程

Eclipse安装Spring Tool Suite之后,可以直接在File–>New–>Project–>
选择Spring–>Spring Starter Project输入Name(项目名称)、Group(这个为公司网址)以及Package(应用包名)–>Finish即可
创建完成时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.xykj</groupId>
    <artifactId>hello</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>hello</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

spring-boot-starter:核心模块,包括自动配置支持、日志和YAML
spring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito

在dependencies中引入Web模块,需添加spring-boot-starter-web模块

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

然后在main下的Application.java中添加方法即可:

@SpringBootApplication
@RestController
public class SpringdemoApplication {

    @RequestMapping("/")
    public String greeting() {
        return "Hello World!";
    }

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

启动:右单机Application.java类Run As–>Spring Boot App,然后在浏览器输入http://127.0.0.1:8080/ 访问 即可看到结构

猜你喜欢

转载自blog.csdn.net/AHAI1078766113/article/details/80848871
今日推荐