在我的 pom 中,我有 ehcache 2 依賴項
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
問題是,在應用程式構建期間,我們對漏洞進行了 grype 檢查,它會檢測到此依賴項中的幾個庫:
NAME INSTALLED FIXED-IN VULNERABILITY SEVERITY
jackson-databind 2.11.1 2.12.6.1 GHSA-57j2-w4cx-62h2 High
jersey-common 2.31 2.34 GHSA-c43q-5hpj-4crv Medium
jetty-server 9.4.39.v20210325 9.4.41 GHSA-m6cp-vxjx-65j6 Low
這有點令人困惑,因為庫以非常奇怪的方式添加到 ehcache jar - 不像依賴項,而是檔案夾“rest-management-private-classpath”中擴展名為 *.class_terracotta 的檔案,如 螢屏截圖所示
由于這種方法,不能在 pom 檔案中覆寫或排除庫版本。
可能正確的方法是從 ehcache 2 遷移到 3,但這可能需要一些時間,我想知道是否有任何快速的解決方案可以將這些庫從 ehcache jar 中排除或覆寫它們的版本?
PS 當我檢查 ehcache 檔案時,它說應該使用 pom 型別添加依賴項
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.4</version>
<type>pom</type>
</dependency>
但是如果我在我的 pom 中將其更改為這種型別 - 快取管理器未初始化并且我收到此錯誤
Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.session.JdbcSessionConfiguration$SpringBootJdbcHttpSessionConfiguration': Unsatisfied dependency expressed through method 'setTransactionManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: 'entityManagerFactory' depends on missing bean 'cacheManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cacheManager' available
uj5u.com熱心網友回復:
有時庫工件以多種方式發布。
一種方法是打包所有需要的依賴項,因此可以按原樣使用而無需添加額外的依賴項。挑戰正是您在此處觀察到的 - 無法排除或更改那些嵌入式依賴項。org.hamcrest:hamcrest-all是一個例子。
一些庫也有一個“更輕”的版本——一個只包含特定工件的類等。然后,我們可以顯式地添加其他依賴項來獲得所需的功能——我們完全可以控制使用哪些版本等。org.hamcrest:hamcrest-core并且org.hamcrest:hamcrest-library是部分替代品hamcrest-all(可能需要更多依賴項才能獲得-all版本提供的完整功能)。
就我個人而言,我更喜歡第二種方式,因為遇到的問題很難找到和除錯。
因此,這里的修復是查看是否有 Ehcache 版本 2 的“輕量級”版本并切換到它(以及核心功能所需的任何其他依賴項)。
如果沒有,并且您絕對無法切換到版本 3,那么您可以繼續使用maven-shade-plugin來重建 ehcache jar,過濾掉額外的依賴項。我強烈建議不要這樣做,因為誰想在每次版本更新時重建 ehcache jar?如果不太可能(現在已損壞)庫無論如何都無法正常作業,那也是有可能的。另外,它必須手動上傳到團隊的工件存盤庫,最好使用分類器或不同的組 ID,以明確這不是官方版本。如果所有這一切都讓你頭暈目眩,那是進行升級的一個很好的理由。:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/464845.html
