Yu&Spring Boot环境配置的那些事

一、写在最最前面

感谢项目的这段难忘(美好但不太友好)的经历
感谢厉害又耐心的学长@谭 @朱 @程 ……
还要这段时间帅气的我
哈哈哈哈哈哈

二、各种环境配置

写在最前面:环境配置就是讲究细心耐心专心!!!
真的差一个就没了啊兄弟!!!
尤其是各种环境第一次的配置,又不知道是哪错了,只能重头再来。第二次心态会更崩,恶性循环。亲身体验那个绝望哈哈哈

1.JDK配置

如下:

 1.下载JDK

(360助手也可以下载JDK哈哈哈,神奇)
首先到官网下载最新版JDK:Oracle官网下载
Accept License Agreement–>下载适合自己pc版本的jdk(x86是32位,x64是64位)

 2.开始安装JDK

选择安装路径,可以不安装在C盘,记住安装到哪就行了,默认也行,我安装在
C:\Program Files\Java\jdk1.8.0_131
(如果你也是idea项目,可以选择和我一样,省事哈哈哈)

 3.安装

安装过程中会跳出Jre的安装界面,一定!!放到和之前JDK在同一个文件夹下(原因:记忆有点要遥远了,While我还记得当时自作聪明后,这里卡了好久)。
然后直接下一步开始安装

 4.环境变量配置

①右击,计算机——属性——高级系统设置——打开环境变量的配置窗口,在系统环境变量一栏点击新建。(后面就不放图了哈)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
②新建环境变量,变量名为:JAVA_HOME,变量值为之前JDK的安装路径,此处安装在:C:\Program Files\Java\jdk1.8.0_131
(可以在系统变量下新建,这样可以为每个登录该pc的用户都配置,如果在用户变量中新建,则只为当前用户配置,此处以在系统变量下新建为例)
③找到Path变量–>编辑
④如果是win10系统,则进入后界面如下,选择新建两个环境变量,
一个值为:%JAVA_HOME%\bin
另一个为:%JAVA_HOME%\jre\bin
(此处笔者已经配置好)
⑤如果是win7及之前的系统则进入后界面如下:
在变量值最后输入 %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
(注意原来Path的变量值末尾有没有;号,如果没有,先输入;号再输入上面的代码)

配置好如图(后面就不放图了哈)
在这里插入图片描述
在这里插入图片描述
最后验证一下

1.win + R–>输入cmd,进入cmd命令行
2.输入:java -version 就可以查看版本信息,如果显示如下信息,则表示环境配置成功
在这里插入图片描述

2.Maven配置

如下:
前置条件:已安装jdk(见上面)

 1.下载maven

下载地址:http://maven.apache.org/download.cgi
官网下载apache-maven-3.5.2.bin .zip 文件

 2.解压apache-maven-3.5.2

和JDK一样,选择安装路径,我安装在
D:\apache-maven-3.6.3
(如果是idea项目,可以选择一样,省事)

 Maven目录分析:
 bin文件夹:含有mvn运行的脚本
 boot文件夹:含有plexusrlds类加载器框架
 conf文件夹:含有settings.xml配置文件
 lib文件夹:含有maven运行时所需要的java类库

 3.配置环境变量 复制maven路径

 ①新建环境变量MAVEN_HOME

D:\apache-maven-3.6.3 (maven路径)

 ②设置环境变量Path

编辑Path,增加“%MAVEN_HOME%\bin”

 ③新建环境变量MAVEN_OPTS

通常需要设置MAVEN_OPTS的值为
-Xms128m -Xmx512m
原因:Java默认的最大可用内存往往不能够满足Maven运行的需要,比如在项目较大时,使用Maven生成项目站点需要占用大量的内存,如果没有该配置,则容易有java.lang.OutOfMemeoryError

 ④修改配置文件(右键编辑文件)

通常我们需要修改解压目录下conf/settings.xml文件,这样可以更好的适合我们的使用

此处注意:所有的修改一定要在注释标签外面,不然修改无效。Maven很多标签都是给的例子,都是注释掉的。

文章最后附上我的整个Settings.xml文件配置,如果地址什么都和我一样就可以用
1)本地仓库位置修改
在标签内添加自己的本地位置路径
Default的意思是,如果本地位置失败,就会去那里

 <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>D:\apache-maven-3.6.3\repository</localRepository>

2)修改maven默认的JDK版本
在标签下添加一个标签,修改maven默认的JDK版本。

<profile>     
    <id>JDK-1.8</id>       
    <activation>       
        <activeByDefault>true</activeByDefault>       
        <jdk>1.8</jdk>       
    </activation>       
    <properties>       
        <maven.compiler.source>1.8</maven.compiler.source>       
        <maven.compiler.target>1.8</maven.compiler.target>       
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>       
    </properties>       
</profile>

3 )添加国内镜像源
添加标签下,添加国内镜像源,这样下载jar包速度很快。默认的中央仓库有时候甚至连接不通。一般使用阿里云镜像库即可。这里我就都加上了,Maven会默认从这几个开始下载,没有的话就会去中央仓库了。

<!-- 阿里云仓库 -->
<mirror>
    <id>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
最后的前一步:验证一下

1.win + R–>输入cmd,进入cmd命令行
2.输入:mvn -v 就可以查看版本信息,如果显示如下信息(划重点:Maven的版本号),则表示环境配置成功
在这里插入图片描述

 最后安装jar包到本地仓库

mvn install

常用命令
mvn -v #查看版本信息

mvn compile #编译

mvn test # 测试

mvn package #打包成jar的形式

mvn clear #删除target

mvn install #安装jar包到本地仓库

至此,Maven配置告一段落

3.Tocmat配置

1.下载

下载地址:http://tomcat.apache.org/
我是下载的.zip文件(免安装版本),注意系统是32位和64位的

2.解压

直接解压缩,找到目录bin下的startup.bat,启动Tomcat;shutdown.bat:关闭Tomcat

3、Tomcat配置

配置Tomcat之前,要保证jdk已经配置完成

同上,右击,计算机——属性——高级系统设置——打开环境变量的配置窗口,在系统环境变量一栏点击新建。

切记,安装Tomcat时,在其字母周围不要存在空格,否则最后导致配置不成功(亲身证明哈哈哈)

在系统变量里点新建:

变量名:CATALINA_BASE
变量值:C:\tomcat\apache-tomcat-8.5.53;

再新建:

变量名:CATALINA_HOME
变量值:C:\tomcat\apache-tomcat-8.5.53;

点击确定后在classpath中加入

%CATALINA_HOME%\common\lib\servlet-api.jar;
(注意加的时候在原变量值后加英文状态下的“;”)

在path中加入

%CATALINA_HOME%\bin;
(注意加的时候在原变量值后加英文状态下的“;”)

Tomcat就配置好了

验证是否配置成功

运行Tomcat,点击启动(或Start service)后,打开浏览器,敲入http://localhost:8080,如果出现页面,那么配置成功。如下:
在这里插入图片描述

4.IntelliJ IDEA环境设置

如下:

1.下载

官网的下载链接:IDEA官网下载地址
建议下载专业版,社区版缺少很多功能,体验感没专业版好(可以试用一段时间,学生可以申请一年免费,网上有破解版)

2.开始安装IntelliJ IDEA

①选择安装路径;
②上面是创建桌面图标,选择电脑对应的版本;
下面的可以全选,表示什么格式的文件可直接关联到IDEA,用IDEA来打开(我考虑到日常还是低配的更锻炼思维能力,就没有选)
③下一步直接install

3.启动刚安装好的IDEA

①如果第一次安装,就直接不导入设置,ok
②选个喜欢的主题,然后next
③直接next
④直接start

5.IntelliJ IDEA项目环境配置

(写在前面给我自己看的:如果对自己的代码没有那么自信的话,一定要直接搭建Spring Boot,然后用postman做接口测试。
 原因:如果用IntelliJ IDEA自带的Maven和tomcat,他是直接跑整个项目,有错误就不给搭建,大神的错误追踪法对于我这种小白完全不适用,,,
 回忆起在这也卡了好久表示太难了,,,)

由于这次的项目是学长建好的逻辑框架,所以从GitHub下载项目文件,然后拖动到 IntelliJ IDEA,就打开了,这里直接从打开后的配置开始说起:

  1.基础配置:
   IDEA内置了Maven环境,默认采用Maven解决项目依赖问题。

在这里插入图片描述
①Setting要配置的

 1)JRE配置

在这里插入图片描述

2)Maven配置
这里比较关键昂,我当时在这卡了三天,试了各种方法哈哈哈
(如果遇到麻烦的话,可以留言哦,说不准我遇到过了呢)

顺序和注意事项都标好啦
在这里插入图片描述
在这里插入图片描述
原因:此处勾选,当修改pom文件时,Maven就能帮我们自动导包了

3)Spring Boot配置

点这
在这里插入图片描述
会出现下面这个
选择左上角的加号,找到里面的Spring Boot

(如果没有Spring Boot,可以自行百度。因为我当时也没有,但不记得是改的哪里了)

就会出现这个,然后配置
在这里插入图片描述
这有问题对吧哈哈哈哈,我也是。学长告诉我这样弄就好了
在这里插入图片描述
选择project as a maven

可以看一下自己的最右边:

有四个哦,如果没有,就检查一下相关配置
在这里插入图片描述
然后就好了,环境配置暂时告一段落

6.postman配置

1.下载

官网:https://www.getpostman.com/downloads/
在这里插入图片描述

2.创建账号或者用谷歌浏览器账号登录

我已经弄完了,借的图(下面有作者大大的连接昂,如有侵权请联系我删掉)
在这里插入图片描述

 3.请求方式是get post什么的,根据自己的需求选

在这里插入图片描述

简单逻辑就是:
搜索用get
添加删除和修改用post

最后,有返回值,就成功了

中心思想:返回值数据都是给前端看的或者用的

如果代码和我一样有返回前端的请求:

return AjexResult.success();

那么操作成功的返回值类似于这样:
{
"msg": "操作成功",
"code": 0
}

三、项目

具体项目的一些易错点也有总结,但就不放出来了
皮一下很开心
在这里插入图片描述

四、笔记

1. Spring Boot相关

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2. Git基本命令

 1.安装

不想介绍了哈哈哈,可以百度的到

2.基本命令

一些笔记,可以稍微了解一下
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

以下是谭学长整理的
初始化                       
git init    
将远端仓库标为origion
git remote add origin http:仓库名.git
从远程仓库拉取文件 
git pull --rebase origin master

……………………将自己的controller等文件放到拉取下的文件的相应位置………………

标记修改文件
git add .
将修改的标记文件加入本地仓库
git commit -m "这里写你本次修改的内容"
推到远程仓库
git push -u origin master

五、Setting.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>D:\apache-maven-3.6.3\repository</localRepository>

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
	  -->
    <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>central</mirrorOf>
      <name>nexus-aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
    
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

参考文献:
https://blog.csdn.net/qq_33215972/article/details/73693140
https://blog.csdn.net/u010282984/article/details/80884810
https://blog.csdn.net/qq_37591637/article/details/88655294
https://blog.csdn.net/huo920/article/details/82082403
参考视频:
b站up主:湖北大学瑞翼工坊

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是Yu欸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值