JavaWeb新建项目,作者常用maven依赖,依赖笔记

文章目录

  • 一、Spring版本管理依赖
  • 二、SpringBoot启动需要的依赖
  • 三、数据库连接的依赖
  • 四、SpringCloud系列常用依赖
  • 作者写的Demo
    • pom文件
  • 其他

一、Spring版本管理依赖

  • 有这个可以避免很多依赖版本不匹配的问题
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.3.1.RELEASEversion>
        <relativePath/> 
    parent>

二、SpringBoot启动需要的依赖

  • 启动依赖
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-autoconfigureartifactId>
        dependency>
  • 测试启动依赖
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>

三、数据库连接的依赖

  • 数据库连接驱动
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency>
  • mybatis-plus的依赖
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-plus-boot-starterartifactId>
            <version> 3.4.0version>
        dependency>
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-plus-annotationartifactId>
            <version> 3.4.0version>
        dependency>
  • tk_mybatis的依赖
     <dependency>
        <groupId>tk.mybatisgroupId>
        <artifactId>mapper-spring-boot-starterartifactId>
        <version>2.1.5version>
    dependency>

    <dependency>
        <groupId>tk.mybatisgroupId>
        <artifactId>mapperartifactId>
        <version>4.1.5version>
    dependency>
  • 这几个mybatis会冲突,在依赖中使用下面这段代码即可
            <exclusions>
                <exclusion>
                    <groupId>org.mybatisgroupId>
                    <artifactId>mybatisartifactId>
                exclusion>
                <exclusion>
                    <groupId>org.mybatisgroupId>
                    <artifactId>mybatis-springartifactId>
                exclusion>
            exclusions>

四、SpringCloud系列常用依赖

  • Eureka(服务注册与发现)
<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
dependency>
  • Ribbon(客户端负载均衡):
<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-netflix-ribbonartifactId>
dependency>
  • Feign(声明式服务调用):
<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-openfeignartifactId>
dependency>
  • Hystrix(服务容错保护):
<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-netflix-hystrixartifactId>
dependency>
  • Zuul(API 网关):
<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-netflix-zuulartifactId>
dependency>

作者写的Demo

pom文件


<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.0modelVersion>

    <groupId>org.examplegroupId>
    <artifactId>test_projectartifactId>
    <version>1.0-SNAPSHOTversion>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.3.1.RELEASEversion>
        <relativePath/> 
    parent>


    <properties>
        <maven.compiler.source>8maven.compiler.source>
        <maven.compiler.target>8maven.compiler.target>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-autoconfigureartifactId>
        dependency>
    dependencies>

project>

其他

  • SpringBoot启动类
    package com.example.user;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class UserApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(UserApplication.class, args);
        }
    
    }
    
    

你可能感兴趣的:(其他,maven,笔记,java)