關(guān)于Spring配置方面的一點(diǎn)心得(io.spring.platform)
最近在配置Maven項(xiàng)目,也就是使用io.spring.platform來(lái)進(jìn)行管理自己的Spring項(xiàng)目的各種依賴,但是后來(lái)的配置過(guò)程中發(fā)現(xiàn)不簡(jiǎn)單,因?yàn)閯傞_始我是使用
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Cairo-SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
但是后來(lái)總是在啟動(dòng)項(xiàng)那里發(fā)現(xiàn),不是少這個(gè)方法就是少那個(gè)方法,列舉其中的一個(gè)錯(cuò)誤:springboot項(xiàng)目啟動(dòng)報(bào)錯(cuò)Attribute 'proxyBeanMethods' in annotation [org.springframework.
后來(lái)在一些小伙伴的討論中,發(fā)現(xiàn)有可能是版本的問(wèn)題,因?yàn)樵诓煌姹究赡軙?huì)有一些方法不存在或者過(guò)時(shí)廢棄的情況出現(xiàn),導(dǎo)致在索引依賴的時(shí)候出現(xiàn)找不到方法的情況。
那個(gè)提出問(wèn)題的小伙伴最后解決了,他是將2.1.4.RELEASE升級(jí)為2.2.0.RELEASE? 這個(gè)回答啟發(fā)了我,于是我去搜索Cairo-SR7版本的io.spring.platform對(duì)應(yīng)的springBoot版本,結(jié)果它對(duì)應(yīng)的是2.0.8.RELEASE,在官方的文檔中發(fā)現(xiàn)它已經(jīng)排在最后,原來(lái)這個(gè)io.spring.platform已經(jīng)終止研發(fā)了,官方?jīng)Q定使用spring-boot-starter來(lái)進(jìn)行包管理
https://spring.io/projects/platform
End of Life
The Platform will reach the end of its supported life on 9 April 2019. Maintenence releases of both the Brussels and Cairo lines will continue to be published up until that time. Users of the Platform are encourage to start using Spring Boot’s dependency management directory, either by using spring-boot-starter-parent as their Maven project’s parent, or by importing the spring-boot-dependencies bom.
翻譯:
壽命終止該平臺(tái)將于2019年4月9日終止其受支持的壽命。Brussels和 Cairo生產(chǎn)線的維護(hù)版本將繼續(xù)發(fā)布,直到那時(shí)為止。 鼓勵(lì)平臺(tái)用戶開始使用Spring Boot的依賴項(xiàng)管理目錄,方法是將spring-boot-starter-parent用作其Maven項(xiàng)目的父級(jí),或者導(dǎo)入spring-boot-dependencies bom。
于是我開始觀看我們一般的spring項(xiàng)目的包依賴的方式,比如:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/><!-- lookup parent from repository -->
</parent>
<groupId>life.majiang.community</groupId>
<artifactId>community</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>community</name>
<description>Spring Boot community</description>
但是在我使用該方式之后出現(xiàn)了,全部依賴無(wú)法找到的情況,我猜測(cè)可能一個(gè)項(xiàng)目的包管理的方式可能只有一個(gè),我有兩個(gè),可能會(huì)出現(xiàn)混亂,于是我還是在<dependencyManagement>的標(biāo)簽下面添加spring-boot的依賴管理:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
于是build成功,可以運(yùn)行。
但是你在打開右邊欄的Maven 的時(shí)候你會(huì)發(fā)現(xiàn),你的部分依賴會(huì)報(bào) unknow,也就是找不到的錯(cuò)誤,這個(gè)其實(shí)是一種思維定勢(shì),在之前io.spring.platform管理的springboot 1.X時(shí)代的確不用管理這些依賴,只要寫上依賴的名字,然后io.spring.platform會(huì)自動(dòng)配置版本來(lái)達(dá)到兼容,但是現(xiàn)在不是用這個(gè)方式之后,顯然這種方式已經(jīng)不在適用了,對(duì)于一些依賴你要明確它的版本,有些則可以不寫,可以參考我下面的pom.xml內(nèi)容:
<?xmlversion="1.0" encoding="UTF-8"?>
<projectxmlns="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">
<parent>
<artifactId>imooc-security</artifactId>
<groupId>com.imooc.security</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
?
<artifactId>imooc-security-core</artifactId>
<packaging>jar</packaging>
?
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-config</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
?
</project>
這樣IDEA就會(huì)自動(dòng)下載相應(yīng)的依賴,于是就可以了。