相关推荐recommended
JDK17 SpringBoot3 整合常见依赖
作者:mmseoamin日期:2023-12-21

JDK版本:17

SpringBoot 整合Mybatis Plus 、Redis等

JDK17 SpringBoot3 整合常见依赖,在这里插入图片描述,第1张

依赖文件



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        3.1.0
         
    
    com.xzm
    server
    0.0.1-SNAPSHOT
    Server
    Server
    
        17
    
    jar
    
        
        
            org.springframework.boot
            spring-boot-starter-data-jpa
        
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.projectlombok
            lombok
            true
        
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.5.3.1
        
        
            mysql
            mysql-connector-java
            8.0.33
        
        
            com.alibaba
            druid-spring-boot-starter
            1.2.16
        
        
        
            org.springframework.boot
            spring-boot-starter-validation
        
        
        
            com.alibaba
            fastjson
            2.0.32 
        
        
        
            org.springframework.boot
            spring-boot-starter-data-redis
            3.0.0
        
    

文件位置视图

tree .\src\main

├─java

│ └─com

│ └─xzm

│ ├─common

│ ├─configs

│ ├─controller

│ ├─domain

│ ├─intercepts

│ ├─mapper

│ ├─service

│ │ └─impl

│ └─utils

└─resources

└─mapper**

application.yaml配置文件

#Spring
spring:
  #Mysql
  datasource:
    url: jdbc:mysql://localhost:3306/staticdb?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
  #Redis
  data:
    redis:
      host: localhost
      password: 123456
      database: 0
      port: 6379
server:
  port: 8080
# MyBatis-Plus Config
mybatis-plus:
  log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.xzm.generator.domain
logging:
  level:
    com.baomidou.mybatisplus: debug

SpringBoot 启动类

package com.xzm;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
@SuppressWarnings({"all"})
@MapperScan(basePackages = "com.xzm.mapper") // 指定 Mapper 接口所在的包
@Slf4j
public class ServerApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ServerApplication.class, args);
        log.info("访问链接:\thttp://localhost:"+context.getEnvironment().getProperty("server.port"));
        log.info("启动成功");
    }
}

控制台

 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.0)
2023-12-19T20:31:35.035+08:00  INFO 16132 --- [           main] com.xzm.ServerApplication                : Starting ServerApplication using Java 17.0.8 with PID 16132 (W:\IDEA WorkSpace\Server\target\classes started by Administrator in W:\IDEA WorkSpace\Server)
2023-12-19T20:31:35.037+08:00  INFO 16132 --- [           main] com.xzm.ServerApplication                : No active profile set, falling back to 1 default profile: "default"
2023-12-19T20:31:35.682+08:00  INFO 16132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2023-12-19T20:31:35.683+08:00  INFO 16132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-12-19T20:31:35.710+08:00  INFO 16132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 19 ms. Found 0 JPA repository interfaces.
2023-12-19T20:31:35.725+08:00  INFO 16132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2023-12-19T20:31:35.726+08:00  INFO 16132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2023-12-19T20:31:35.736+08:00  INFO 16132 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1 ms. Found 0 Redis repository interfaces.
2023-12-19T20:31:36.278+08:00  INFO 16132 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-12-19T20:31:36.286+08:00  INFO 16132 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-12-19T20:31:36.287+08:00  INFO 16132 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.8]
2023-12-19T20:31:36.361+08:00  INFO 16132 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-12-19T20:31:36.361+08:00  INFO 16132 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1285 ms
2023-12-19T20:31:36.486+08:00  INFO 16132 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-12-19T20:31:36.760+08:00  INFO 16132 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@22f8adc2
2023-12-19T20:31:36.762+08:00  INFO 16132 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-12-19T20:31:36.793+08:00  INFO 16132 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-12-19T20:31:36.837+08:00  INFO 16132 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.2.2.Final
2023-12-19T20:31:36.839+08:00  INFO 16132 --- [           main] org.hibernate.cfg.Environment            : HHH000406: Using bytecode reflection optimizer
2023-12-19T20:31:36.938+08:00  INFO 16132 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2023-12-19T20:31:37.050+08:00  INFO 16132 --- [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2023-12-19T20:31:37.114+08:00  INFO 16132 --- [           main] org.hibernate.orm.dialect                : HHH035001: Using dialect: org.hibernate.dialect.MySQLDialect, version: 8.0.30
2023-12-19T20:31:37.179+08:00  INFO 16132 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2023-12-19T20:31:37.320+08:00  INFO 16132 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-12-19T20:31:37.323+08:00  INFO 16132 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-12-19T20:31:37.735+08:00 DEBUG 16132 --- [           main] c.b.m.e.s.MybatisSqlSessionFactoryBean   : Parsed mapper file: 'file [W:\IDEA WorkSpace\Server\target\classes\mapper\ResourcesTagsMapper.xml]'
2023-12-19T20:31:37.759+08:00 DEBUG 16132 --- [           main] c.b.m.e.s.MybatisSqlSessionFactoryBean   : Parsed mapper file: 'file [W:\IDEA WorkSpace\Server\target\classes\mapper\UserMapper.xml]'
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.5.3.1 
2023-12-19T20:31:37.869+08:00  WARN 16132 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-12-19T20:31:38.251+08:00  INFO 16132 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-12-19T20:31:38.261+08:00  INFO 16132 --- [           main] com.xzm.ServerApplication                : Started ServerApplication in 3.563 seconds (process running for 4.094)
2023-12-19T20:31:38.265+08:00  INFO 16132 --- [           main] com.xzm.ServerApplication                : 访问链接:	http://localhost:8080
2023-12-19T20:31:38.265+08:00  INFO 16132 --- [           main] com.xzm.ServerApplication                : 启动成功