spring in action 5這本書,以實戰爲主,感覺挺不錯。
但是書中默認使用spring tool suite作爲開發IDE。但是在公司裏面,sts並不常見,主流是使用IDEA進行開發。個人對idea也不太熟悉,所以肯定是希望在idea上來進行實踐,學習spring的同時,也學習一下idea的使用。
以下簡單記錄在idea上運行taco-cloud項目的步驟。
-
下載項目代碼
https://github.com/habuma/spring-in-action-5-samples -
設置maven倉庫爲國內鏡像倉庫
settings.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<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>D:\mavenRepository</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
<mirror>
<id>alimaven-central</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk18</id>
<activation>
<jdk>1.8</jdk>
<activeByDefault>true</activeByDefault>
</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>
</profiles>
</settings>
然後在IDEA中指定maven使用此配置文件。
-
maven install 編譯
這一步一直報錯:
Failure to find org.openjfx:javafx.base:jar:linux:11.0.0-SNAPSHOT in xxx
網上搜到一個解釋:
https://qa.1r1g.com/sf/ask/3768451011/
說是由於org.hibernate.validator這個組件引起的,6.0.11版本有問題,升級到6.0.12可以解決。
由於pom.xml中並沒直接依賴這個組件,而是經過spring-boot-starter-web間接引入的,而各個組件的版本又都是由spring-boot-starter-parent決定的,需要需要升級spring-boot-starter-parent的版本。
登陸到aliyun鏡像上,一步一步點開,發現最新版本是2.2.2,所以修改爲2.2.2後,重新編譯,問題解決。
-
啓動toco-cloud
這一步非常簡單,main函數入口在TacoCloudApplication中,編譯成功的前提條件下,右鍵->run TacoCloudApplication這個類即可,會自動啓動tomacat。
-
瀏覽器便可以正常訪問了