欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IntelliJ?IDEA社區(qū)版2021.3配置SpringBoot項目詳細教程及失敗案例

 更新時間:2024年03月21日 10:23:51   作者:是煙花哈  
IntelliJ?IDEA?2021.3.3是一款集成開發(fā)環(huán)境,用于Java和其他編程語言的開發(fā),下面這篇文章主要給大家介紹了關于IntelliJ?IDEA社區(qū)版2021.3配置SpringBoot項目詳細教程及失敗案例的相關資料,需要的朋友可以參考下

一、SpringBoot的定義

Spring 的誕?是為了簡化 Java 程序的開發(fā)的,? Spring Boot 的誕?是為了簡化 Spring 程序開發(fā)的。

Spring Boot 翻譯?下就是 Spring 腳?架,就是為了快速開發(fā) Spring 框架?誕?的

Spring Boot 項?的?大特點:約定?于配置。較于Spring需要配置Bean的掃描路徑,而SpringBoot就不需要

二、Spring Boot 優(yōu)點

  • 快速集成框架,Spring Boot 提供了啟動添加依賴的功能,?于秒級集成各種框架。
  • 內置運?容器,?需配置 Tomcat 等 Web 容器,直接運?和部署程序。
  • 快速部署項?,?需外部容器即可啟動并運?項?。
  • 可以完全拋棄繁瑣的 XML,使?注解和配置的?式進?開發(fā)。
  • ?持更多的監(jiān)控的指標,可以更好的了解項?的運?情況。

SpringBoot的核心:

1、快速添加依賴

2、內置web容器

3、自動裝配(即SpringBoot自動構建復雜對象,構建好的對象可以直接使用)

三、創(chuàng)建一個springboot的項目

因為我們?的 Idea 社區(qū)版2021.3,選擇安裝SpringBoot插件才能創(chuàng)建 Spring Boot 項目。

SpringBoot插件名字為

 接下來開始正式創(chuàng)建SpringBoot項目:

1、先選擇file->new->project

2、選擇Spring Initializr,選擇國外的默認配置源

3、添加項目的依賴

一般是Web項目,所以我們勾選最基本的 Web選項,選擇SpringBoot Devtools用于實現(xiàn)熱部署,其他可以等用到的時候再添加。

  • Spring Boot Devtools:實現(xiàn)熱部署
  • Lombok:Java注解
  • Spring Web: 外部服務

SpringBoot版本選擇后綴不帶英文字母的穩(wěn)定版本,其中低版本的比較穩(wěn)定

點擊下一步,命名自己項目的名字和保存地址,點擊finash,等待項目的創(chuàng)建

開始進行啟動類初始化:右擊 項目名,選擇“ Add Framework Support

如果出現(xiàn)以下藍色且右上角帶有三角形則啟動類初始化成功

點擊運行啟動類,出現(xiàn)以下圖形則說明一個SpringBoot項目已經構建完成

四、使用IDEA創(chuàng)建SpringBoot失敗案例

由于SpringBoot版本可能與IDEA某些版本產生沖突導致無法創(chuàng)建成功,失敗的案例有如下幾種:

1、Maven缺少plugins和dependencies兩個選項

2、Cannot resolve symbol 'springframework' 錯誤異常

解決方法:

(1)第一種方法:刪除Maven本地的配置文件,重新配置國內阿里源在進行重新下載Maven進行加載

阿里源文件settings.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>
  -->

  <!-- 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>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>        
      </mirror>
    <!-- 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>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</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>

(2)第二種方法:創(chuàng)建一個空項目,然后以新建模塊的方式 創(chuàng)建新的SpringBoot項目

 以這種方式,沒有感覺idea 版本和 maven版本存在沖突問題

接下來的步驟就和正常創(chuàng)建SpringBoot的步驟一模一樣了,完成以上全部步驟之后點擊啟動類運行,如果能運行成功則SpringBoot項目就創(chuàng)建成功了。

異常案例:若創(chuàng)建Maven時,pom.xml文件為灰色,沒有變成藍色時,此時右鍵點擊pom.xml文件,再點擊 add as maven project  稍等一會兒導入依賴就可以

說明

之所以沒有配置Tomcat,是因為Spring Boot內置了Tomcat

主要的幾個代碼介紹

1、@SpringBootApplication:Spring Boot項目的核心注解,主要目的是開啟自動配置。;

2、@Configuration:這是一個配置Spring的配置類;

3、@Controller:標明這是一個Spring MVC的Controller控制器;

4、main方法:在main方法中啟動一個應用,即:這個應用的入口;

總結

到此這篇關于IntelliJ IDEA社區(qū)版2021.3配置SpringBoot項目詳細教程及失敗案例的文章就介紹到這了,更多相關IDEA社區(qū)版配置SpringBoot項目內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • java詞法分析器DDL遞歸應用詳解

    java詞法分析器DDL遞歸應用詳解

    這篇文章主要介紹了java詞法分析器DDL遞歸應用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • Java ServletContext對象用法解析

    Java ServletContext對象用法解析

    這篇文章主要介紹了Java ServletContext對象用法解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-05-05
  • Springboot分模塊項目搭建的實現(xiàn)

    Springboot分模塊項目搭建的實現(xiàn)

    在軟件開發(fā)中,利用Spring?Boot進行分模塊項目搭建能夠提高代碼的模塊化和復用性,本文主要介紹了Springboot分模塊項目搭建的實現(xiàn),感興趣的可以了解一下
    2024-10-10
  • java 通過聚合查詢實現(xiàn)elasticsearch的group by后的數(shù)量

    java 通過聚合查詢實現(xiàn)elasticsearch的group by后的數(shù)量

    這篇文章主要介紹了java 通過聚合查詢實現(xiàn)elasticsearch的group by后的數(shù)量,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-12-12
  • SpringBoot如何進行對象復制的實踐

    SpringBoot如何進行對象復制的實踐

    本文主要介紹了SpringBoot 如何進行對象復制,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Spring Boot 搭建 ELK正確看日志的配置流程

    Spring Boot 搭建 ELK正確看日志的配置流程

    這篇文章主要介紹了Spring Boot 搭建 ELK正確看日志的配置流程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03
  • 淺談 JDBC 元數(shù)據(jù)

    淺談 JDBC 元數(shù)據(jù)

    這篇文章主要介紹了JDBC元數(shù)據(jù)的相關內容,涉及一些獲取數(shù)據(jù)源各種信息的方法,具有一定參考價值,需要的朋友可以了解下。
    2017-09-09
  • 解決Spring Security 用戶帳號已被鎖定問題

    解決Spring Security 用戶帳號已被鎖定問題

    這篇文章主要介紹了解決Spring Security 用戶帳號已被鎖定問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • 使用synchronized關鍵字實現(xiàn)信號量的方法

    使用synchronized關鍵字實現(xiàn)信號量的方法

    在Java中,信號量(Semaphore)是一種常用的同步工具,它可以用來控制對共享資源的訪問數(shù)量,下面,我們將使用Synchronized關鍵字來實現(xiàn)一個簡單的信號量,我們的目標是實現(xiàn)一個計數(shù)信號量,其中信號量的計數(shù)指示可以同時訪問某一資源的線程數(shù),需要的朋友可以參考下
    2024-04-04
  • 淺談java多態(tài)的實現(xiàn)主要體現(xiàn)在哪些方面

    淺談java多態(tài)的實現(xiàn)主要體現(xiàn)在哪些方面

    下面小編就為大家?guī)硪黄獪\談java多態(tài)的實現(xiàn)主要體現(xiàn)在哪些方面。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-09-09

最新評論