使用阿里云镜像创建一个Spring Boot项目
作者:mmseoamin日期:2024-04-27

由于现在的idea在创建项目时已经不支持Java8版本了,如果我们还想用8版本,可以使用阿里云镜像创建。所以得改变原有的地址为:https://start.aliyun.com

使用阿里云镜像创建一个Spring Boot项目,第1张

上面是idea专业版创建项目,如果是社区版还需要在创建前安装一个插件 :Spring Boot Helper

不过这个是收费的,想要免费的我们需要如下操作:

  • 1.点击它,然后找版本Version,找到Free版本的,下载。

    使用阿里云镜像创建一个Spring Boot项目,第2张

    • 2.下载完成后,如下操作找到刚刚下载的zip (不需要解压),点击OK后,重启idea即可。

      使用阿里云镜像创建一个Spring Boot项目,第3张

      使用阿里云镜像创建一个Spring Boot项目,第4张

      出现如下所示则为下载成功。

      使用阿里云镜像创建一个Spring Boot项目,第5张


      springboot版本选择2开头的任意版本的。

      使用阿里云镜像创建一个Spring Boot项目,第6张

      1.配置依赖

      创建新项目时可只配置Spring Boot DevTools ,Spring Web 这两个即可。后续通过插件再配置。

      使用阿里云镜像创建一个Spring Boot项目,第7张

      2.改变下载依赖地址

      下载依赖默认的是访问国外,为了让下载依赖的速度更快,右键点击pom.xml找到settings.xml,进去将下载地址修改成阿里云的,然后保存并重启idea。 

      使用阿里云镜像创建一个Spring Boot项目,第8张

      使用阿里云镜像创建一个Spring Boot项目,第9张

      使用阿里云镜像创建一个Spring Boot项目,第10张

       
            alimaven
            aliyun maven
            http://maven.aliyun.com/nexus/content/groups/public/
            central
      
      • 再去设置新项目

        使用阿里云镜像创建一个Spring Boot项目,第11张

        3.下载插件 EditStarters

        此插件能让我们在项目建成以后,还能随时随刻在idea内添加依赖,更方便。

        使用阿里云镜像创建一个Spring Boot项目,第12张

        下载并启用后,在pom.xml里右键

        使用阿里云镜像创建一个Spring Boot项目,第13张

        使用阿里云镜像创建一个Spring Boot项目,第14张

        4.下载插件 Lombok

        常用的setter,getter,Data注解。用于Javabean类中。

        使用阿里云镜像创建一个Spring Boot项目,第15张

        5.进行全局配置

        在resource文件下创建application.yml,或者修改已经存在的后缀。将以下代码写入:

        # 配置数据库的连接字符串
        spring:
        #  jackson:    # 设置全局的时间格式化 但对类型LocalDate不生效
        #    date-format: yyyy-MM-dd
        #    time-zone: GMT+8
          datasource:
            url: jdbc:mysql://127.0.0.1/testblog?characterEncoding=utf8
            username: root
            password: 123456
            driver-class-name: com.mysql.cj.jdbc.Driver
        # 设置 Mybatis 的 xml 保存路径
        mybatis:
          mapper-locations: classpath:mapper/*Mapper.xml
          configuration: # 配置打印 MyBatis 执行的 SQL
            log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
        # 配置打印 MyBatis 执行的 SQL
        logging:
          level:
            com:
              example:
                demo: debug

         6.打包

        项目编写完后,在pom.xml中插入下面代码,注意位置。

        使用阿里云镜像创建一个Spring Boot项目,第16张

            war
            
                blogsystem
            

         使用阿里云镜像创建一个Spring Boot项目,第17张

        打包成功后,jar包就存在target包里。