springboot⽬录结构、重要配置⽂件、重要注解的详解
前⾯2篇博客已经带着⼤家搭建了springboot项⽬,并编写了持久化接⼝部署到tomcat下访问。这⾥我们⼀起补充下springboot的基本信息⼀.springboot简单介绍
springboot是⽬前流⾏的微服务框架,倡导“约定优于配置”,简化spring项⽬搭建及开发过程。springboot提供了很多核⼼的功能,⽐如⾃动化配置、starter简化maven配置、内嵌servlet容器、应⽤监控等功能。稳定的版本后缀带RELEASE。
⼆.⼯程⽬录介绍
1./src/main/java:⽬录下放置所有的java⽂件(源代码)
2./src/main/resource:存放资源⽂件、如静态资源⽂件、配置⽂件、页⾯⽂件等
3./src/main/resource/static:存放静态资源
4./src/mian/resource/application.properties:配置⽂件,springboot⽀持.properties和.yml⽂件
5./src/main/resources/templates:存放模板⽂件如thymeleaf模板⽂件
6./src/test/java:单元测试类java⽂件
7./target:放置编译后的.class⽂件、配置⽂件等
注意:.properties的⽂件优先级⾼于.yml⽂件。
三.⼊⼝类
⼊⼝类的名称是根据项⽬的名称⽣成的,项⽬名称+application
ample.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);//应⽤程序开始运⾏的地⽅
}
}
@springbootapplication:是个组合注解,包含@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan,简化项⽬启动。
四.l⽂件
springboot项⽬下的l主要是存放依赖信息
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"
springboot框架的作用xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.louis.springboot</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-core</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!-- 打包时拷贝MyBatis的映射⽂件 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/sqlmap/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
1.spring-boot-starter-parent是个特殊的starter,⽤来提供相关的maven默认依赖,使⽤它之后,常⽤的包依赖可以省去version标签。
2.spring-boot-starter-web:得到常⽤的web依赖包,⽐如spring-web、spring-webmvc等
3.spring-boot-starter-test:⾃动引⼊与测试相关的包
4.spring-boot-maven-plugin:这是个maven插件,能够以maven的⽅式为应⽤提供springboot的⽀持,即为springboot应⽤提供了执⾏maven 操作的可能。能够将springboot应⽤打包为可执⾏的jar或者war⽂件

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。