2. Architecture of spring-boot

Architecture building steps:

1. Create a new maven project in eclipse

2. Add spring-boot dependencies in pom.xml as follows:

<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>Isenham</groupId>

<artifactId>springBootStudy</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>war</packaging>

 

<!--Spring Boot basic parent class, which contains many necessary jar packages, if you do not use the parent class, you need to rely on these jars yourself -->

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.3.3.RELEASE</version>

</parent>

 

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<java.version>1.8</java.version>

</properties>

 

<!-- Depends on parent, inherits spring-boot-starter-parent method-->

<dependencies>

<!-- Core modules, including auto-configuration support, logging and YAML -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter</artifactId>

</dependency>

<!-- Supports web application development, including Tomcat and spring-mvc -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<!-- Test modules, including JUnit, Hamcrest, Mockito -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

<!--Template Engine-->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

</dependencies>

 

<build>

<plugins>

<!-- spring-boot compilation plugin -->

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>

</project>

 

3.新建一个启动类:SpringApplicationMain.java

package springBootStudy;

 

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

 

/*

 * @Configuration

@EnableAutoConfiguration

@ComponentScan

 == @SpringBootApplication

 关闭特定的自动配置:@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

 */

@SpringBootApplication

public class SpringlicationMain {

private static Logger logger = LoggerFactory.getLogger(SpringlicationMain.class);

 

public static void main(String[] args) {

logger.info("-------------开始启动-------------");

SpringApplication.run(SpringlicationMain.class, args);

//关闭banner,方式1

//SpringApplication app = new SpringApplication(SpringApplicationMain.class);

//app.setShowBanner(false);

//app.run(args);

//关闭banner,方式2

//new SpringApplicationBuilder(SpringApplicationMain.class).showBanner(false).run(args);

logger.info("-------------启动成功-------------");

}

}

4.在resources目录下新建三个文件:application-dev.properties、application-prod.properties、application.properties

其实需要application.properties文件即可,这个是最重要的,其他两个只是用来分测试和生产的两种配置,在这里一起说一下application.properties怎么调用其他不同的配置

application.properties里面写:spring.profiles.active=dev,这就代表调用的是application-dev.properties这个配置,如果写成spring.profiles.active=prod,这就代表调用的是application-prod.properties这个配置,

application.properties这个配置的内容之后会逐步出现,这暂不描述。

右键运行这个main项目就启动成功了,spring-boot搭建的最基本架构就是这样。

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326946291&siteId=291194637