spring-boot是一个快速构建环境的一套框架,其设计理念是尽可能的减少xml的配置,用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

  废话不多说,关于spring-boot是什么具体请百度。

  官网:http://projects.spring.io/spring-boot

  1. spring-boot是一个mavan项目,所以其使用的jar包全部是通过maven管理,当然,使用maven也是非常方便的。

    首先上我的项目目录结构:

      【spring-boot】快速构建spring-boot微框架

    spring-boot打出来的包是一个可执行jar包的状态,使用的是内置的tomcat服务器,所以不需要将项目转成EJB项目。

  2.设置pom.xml文件

    使用过maven的朋友都知道,maven通过pom文件的依赖来进行管理jar包,所以核心也是这个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.lclc.boot</groupId>
    <artifactId>boot-cache</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <!--Spring Boot基础父类,其中包含了很多必要的jar包,如果不使用父类,则需要自己去依赖这些jars -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.3.RELEASE</version>
    </parent>
    <dependencies>
        <!-- web程序的启动项依赖,通过此依赖可引入内嵌的tomcat等web必须的jars -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- spring-data-jpa程序的启动项依赖,底层为hibernate实现,若不使用此框架则可以依赖其他的orm框架 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- thymeleaf程序的启动项依赖,spring-boot对thymeleaf模板引擎支持最好,建议模板引擎使用此框架 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!-- mysql依赖,使用spring-data-jpa需要指定一个数据库方言,用于连接数据库,即mysql驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <!-- 通过maven构建的插件  -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <!-- 仓库,使用spring-boot RELEASE版本需要这些 -->
    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project>
pom.xml

相关文章: