SpringBoot项目依赖注入

image.png

1.Mysql Driver
2.JDBC API
3.添加Mybatis依赖:

    <dependency>
                    <groupId>org.mybatis.spring.boot</groupId>
                    <artifactId>mybatis-spring-boot-starter</artifactId>
                    <version>2.1.3</version>
    </dependency>
*配置:
    mybatis.configuration.default-statement-timeout=30    
    mybatis.configuration.map-underscore-to-camel-case=true
    日志输出:
    logging.level.com.cy=DEBUG

4.Spring MVC依赖:

Web依赖:会配置一个内置的tomcat
<dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
</dependency>
Thymeleaf依赖:
<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
*配置Thymeleaf的地址:
spring.thymeleaf.prefix=classpath:/templates/pages/
spring.thymeleaf.suffix=.html

5.springboot健康监控依赖和配置
1.1 方式1:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
 在浏览器输入  http://localhost/actuator/health
 要想查看详细的应用健康信息需要配置management.endpoint.health.show-details=always
 若想看到更多  配置文件中management.endpoints.web.exposure.include=*
 然后输入  http://localhost/actuator/beans 

1.2 方式2:

运行项目后在BootDashboard中的 show properties 中查看
![image.png](/img/bVbMmWJ)

6.热部署配置(修改了src/main/java下的文件和配置文件自动重启和部署服务器)

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
</dependency>

7.Lombok插件应用

自动将set、get、toString等方法自动添加到.class文件中。
*7.1添加依赖
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>    
*7.2找到lombok.jar的下载地址  然后cmd 运行 java -jar lombok-1.18.12.jar ---->选择sts安装地址
*7.3Lombok 常用注解分析:
    @Setter 用于为描述的类生成setter方法,不包含final修饰属性。
    @Getter 用于为描述的类生成getter方法。 
    @ToString 用于为描述的类添加toString方法。 
    @EqualsAndHashCode 用于为描述的类,生成hashCode和equals方法。 
    @NoArgsConstructor 用于为描述的类生成无参的构造方法。 
    @AllArgsConstructor 用于为描述的类生成包含类中所有字段的构造方法。 
    @Data用于为描述的类生成setter/getter、equals、canEqual、hashCode、toString方法,如为final属性,则不会为该属性生成setter方法。 
    @Slf4J 用于为描述的类添加一个日志属性对象
配置文件:
spring.main.banner-mode=off

spring.datasource.url=jdbc:mysql://localhost:3306/dbgoods?serverTimezone=GMT%2B8&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root

#spring mybatis
mybatis.mapper-locations=classpath:/mapper/goods/*.xml

#Spring log
logging.level.com.py=debug

#SpingMVC Tomcat:port
server.port=80
server.servlet.context-path=/

#Spring thymeleaf config
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/pages/
spring.thymeleaf.suffix=.html

management.endpoints.web.exposure.include=*

流浪成疯
7 声望3 粉丝

学习