SpringBoot实战学习(八) Spring Boot手工搭建

1.目录结构

SpringBoot实战学习(八) Spring Boot手工搭建_第1张图片

2.搭建项目

1.新建Maven项目,同http://blog.csdn.net/egwriket/article/details/79035761
2.pom.xml

<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.wengroupId>
  <artifactId>springBootartifactId>
  <version>0.0.1-SNAPSHOTversion>

     
     <parent>
        <groupId>org.springframework.bootgroupId>
        
        <artifactId>spring-boot-starter-parentartifactId>
        <version>1.3.0.M1version>
        <relativePath/>
    parent>

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

    
    <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>

project>

3.更新项目。项目→右键→Maven→Update Project ,在项目的根包目录下会有一个artifactId+Application命名的规则的入口类(不知道为什么,Ecplise没有,于是手动建立)

package com.wen.springBoot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication//Spring Boot项目核心注解,开启自动配置
public class DemoApplication {

    @RequestMapping("/")
    String index(){
        return "SpringBoot";
    }

    public static void main(String[] args) {//main方法,项目启动入口
        SpringApplication.run(DemoApplication.class, args);
    }
}

3.运行

入口类→右键→Run As→Java Application 待项目部署,
SpringBoot实战学习(八) Spring Boot手工搭建_第2张图片
访问http://localhost:8080
SpringBoot实战学习(八) Spring Boot手工搭建_第3张图片

你可能感兴趣的:(SpringBoot)