Spring Boot 源码阅读初始化环境搭建

2023-03-23 14:30:09 浏览数 (1)

在开始源码阅读之前,需要先搭建一个简易的SSM环境用于测试,这里不过解释怎么搭建,相信都开始看源码了,还不会搭建Demo环境就先去学习下基础。

demo环境地址:https://github.com/jujunchen/Spring-Boot-Demo.git

版本统一:

代码语言:javascript复制
工具:IDEA

JDK:jdk11

Spring Boot 版本:2.7.9

Mybatis Plus 版本:3.5.2

使用 Spring Initializr 创建一个项目

项目pom.xml文件如下

代码语言:javascript复制
<?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 https://maven.apache.org/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.7.9-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <groupId>com.springboot</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Spring-Boot-Demo</name>
    <description>Spring-Boot-Demo</description>
    
    <properties>
        <java.version>11</java.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

</project>

application.yml文件配置如下

代码语言:javascript复制
# Mysql数据库
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
    username: root
    password: 123456

启动项目,打印出如下日志

代码语言:javascript复制
  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.7.9-SNAPSHOT)

2023-01-23 15:23:41.614  INFO 78768 --- [           main] c.s.demo.SpringBootDemoApplication       : Starting SpringBootDemoApplication using Java 11.0.16.1 on 192.168.0.113 with PID 78768 (/Users/chenjujun/java-projects/Spring-Boot-Demo/Spring-Boot-Demo/target/classes started by apple in /Users/chenjujun/java-projects/Spring-Boot-Demo/Spring-Boot-Demo)
2023-01-23 15:23:41.615  INFO 78768 --- [           main] c.s.demo.SpringBootDemoApplication       : No active profile set, falling back to 1 default profile: "default"
2023-01-23 15:23:41.899  WARN 78768 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.springboot.demo]' package. Please check your configuration.
2023-01-23 15:23:42.070  INFO 78768 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-01-23 15:23:42.075  INFO 78768 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-01-23 15:23:42.075  INFO 78768 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.71]
2023-01-23 15:23:42.127  INFO 78768 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-01-23 15:23:42.127  INFO 78768 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 492 ms
 _ _   |_  _ _|_. ___ _ |    _ 
| | |/|_)(_| | |_  |_)||_|_ 
     /               |         
                        3.5.2 
2023-01-23 15:23:42.368  INFO 78768 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-01-23 15:23:42.376  INFO 78768 --- [           main] c.s.demo.SpringBootDemoApplication       : Started SpringBootDemoApplication in 0.982 seconds (JVM running for 1.447)

OK,环境可以用了。

0 人点赞