SpringBoot初始教程之项目结构(一)
SpringBoot初始教程之项目结构
1 简介
spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Features
- Create stand-alone Spring applications
- Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
- Provide opinionated ‘starter’ POMs to simplify your Maven configuration
- Automatically configure Spring whenever possible
- Provide production-ready features such as metrics, health checks and externalized configuration
- Absolutely no code generation and no requirement for XML configuration
上述是官方的英文讲解、大概翻译后如下:
SpringBoot在建立生产中的独立程序上非常简便、只需要一些简便的配置就能运行起来。大致有如下特点:
- 创建独立的Spring applications
- 能够使用内嵌的Tomcat, Jetty or Undertow,不需要部署war
- 提供starter pom来简化maven配置
- 自动配置Spring
- 提供一些生产环境的特性,比如metrics, health checks and externalized configuration
- 绝对没有代码生成和XML配置要求
2. 快速开始
<?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">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>springboot-1</artifactId> <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>
<version>1.4.1.RELEASE</version>
</plugin>
</plugins>
</build>
</project>
这块统一用spring-boot-starter-parent做为parent 所以spring-boot-starter-web不用填写版本号
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
下面这个插件是用来运行Springboot的,通常有两种方式可以运行SpringBoot,一种是通过直接运行main方法,另外一种是通过使用下面的插件运行。
两种方式有差别,一旦项目中需要访问资源的时候就需要通过插件运行,否则无法访问到资源
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.1.RELEASE</version>
</plugin>
上面是maven配置,接下来需要配置整个程序的入口,AppApplication
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(AppApplication.class, args);
}
}
下面写了一个简易的controller,只要运行main方法或者插件,就能够正常访问了。这块需要注意,controller跟AppApplication放在一个包下面,
如果不再一个下面需要配置扫描的包
@RestController
public class IndexController {
@GetMapping("/index")
public ResponseEntity helloWord() {
return ResponseEntity.ok("hello word");
}
}
3.配置详解
@SpringBootApplication 这个注解是一个组合注解,聚合了多个注解的功能,具体源码如下
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class))
public @interface SpringBootApplication { //排除自启动项
Class<?>[] exclude() default {}; //排除自动启动的beanName
String[] excludeName() default {}; //扫描包
@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
String[] scanBasePackages() default {}; //扫描类
@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
Class<?>[] scanBasePackageClasses() default {}; }
@EnableAutoConfiguration这个注解是用来启动SpringBoot中的自动配置项目,这个注解是必须加上的,否则无法正常使用因为SpringBoot
默认配置了很多配置项,如下图所示配置在这里面的配置项都会自动进行配置,一部分需要引用其他jar包配置才会生效

application.yaml 文件详解
application.yaml是整个应用程序的配置文件,SpringBoot自动加载,SpringBoot提供针对各种组件的都可以通过application.yaml进行配置,后续再进行详解。

转:http://blog.csdn.net/king_is_everyone/article/details/53069572
SpringBoot初始教程之项目结构(一)的更多相关文章
- SpringBoot初始教程之日志处理(二)
SpringBoot初始教程之日志处理(二) 1.介绍 SpringBoot默认是采用logback进行日志处理.Logback是由log4j创始人设计的又一个开源日志组件.Logback是由log4 ...
- SpringBoot整合Mybatis之项目结构、数据源
已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...
- SpringBoot图文教程15—项目异常怎么办?「跳转404错误页面」「全局异常捕获」
有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1-Spr ...
- .NET CLI简单教程和项目结构
WHAT IS .NET CLI ? .NET 命令行接口 (CLI) 工具是用于开发.生成.运行和发布 .NET 应用程序的跨平台工具链. 来源:.NET CLI | Microsoft Docs ...
- SpringBoot项目结构介绍
一项目结构介绍 springboot框架本身对项目结构并没有特别的要求,但是按照最佳的项目结构可以帮助我们减少可能遇到的错误问题.结构如下: (1)应用主类SpringbootApplication应 ...
- SpringBoot图文教程17—上手就会 RestTemplate 使用指南「Get Post」「设置请求头」
有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1-Spr ...
- SpringBoot+Maven 多模块项目的构建、运行、打包实战
前言 最近在做一个很复杂的会员综合线下线上商城大型项目,单模块项目无法满足多人开发和架构,很多模块都是重复的就想到了把模块提出来,做成公共模块,基于maven的多模块项目,也好分工开发,也便于后期微服 ...
- SpringBoot入门教程(二)CentOS部署SpringBoot项目从0到1
在之前的博文<详解intellij idea搭建SpringBoot>介绍了idea搭建SpringBoot的详细过程, 并在<CentOS安装Tomcat>中介绍了Tomca ...
- Vue入坑教程(二)——项目结构详情介绍
之前已经介绍了关于Vue的脚手架vue-cli的安装,以及一些文件目录介绍.具体可以查看<vue 入坑教程(一)--搭建vue-cli脚手架> 下面简单说一下具体的文件介绍 (一) pac ...
随机推荐
- delphi并行压缩
real case test MM parallel 4x scalable (i7 6700)(on the newer processors will be linear) I did a sma ...
- android 图片
1,setCompoundDrawables(Drawable left, Drawable top,Drawable right, Drawable bottom) 设置图片出现在textView, ...
- luogu P2241 统计方形
题目背景 1997年普及组第一题 题目描述 有一个n*m方格的棋盘,求其方格包含多少正方形.长方形 输入输出格式 输入格式: n,m因为原来数据太弱,现规定m小于等于5000,n小于等于5000(原来 ...
- bzoj3774 最优选择
题目描述: 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bi ...
- UVa-1585-得分
#include <stdio.h> #include <string.h> int main() { char s[100]; int T; scanf("%d&q ...
- mysql5.7 在Centeros 6 下自动安装的shell脚本
概述: 此脚本实现了在Centeros 6版本下自动安装mysql5.7到目录 /opt/mysql-5.7*并且做软连接映射到 /usr/local/mysql,自动修改root密码为:123456 ...
- STM32定时器的两个小难点
TIM1 TIM8 挂在APB2上 一般为72M 也即APB2分频系数为1其余TIMER可以认为都挂在APB1上,一般为36M 也即APB1分频系数为2 或者更大 至少为2 APB1不能超过36M定时 ...
- 【UVA 11181】(条件概率)
题链:https://cn.vjudge.net/problem/UVA-11181 题意 n个人去了超市,已知每个人买东西的概率为p[i],在已知有r个人买了东西的情况下,求实际上每个人买东西的概率 ...
- resultType返回的是集合中的元素类型
https://www.cnblogs.com/start-fxw/p/5900087.html
- Oracle中有关数学表达式的语法
Oracle中有关数学表达式的语法 三角函数 SIN ASIN SINHCOS ACOS COSHTA ...