2016-03-15 114 views
0

我正在使用spring框架和maven工具在java中開發一個MVC web應用程序。HTTP狀態500 - java.lang.LinkageError

我在運行我的應用程序時出現以下錯誤。

HTTP Status 500 - java.lang.LinkageError: loader constraint violation: when resolving method 
"org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, 
org/apache/jsp/redirect_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for the method's defining class, 
org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type org/apache/tomcat/InstanceManager used in the signature 

回答

2

您的WEB-INF/lib Web應用程序的文件夾服務器特定的jar文件。例如:jsp-api.jar,el-api.jar,servlet-api.jar等。如果使用maven進行依賴關係管理,則需要刪除所有這些。

刪除它後,如果您的代碼中出現編譯錯誤,請從項目屬性中添加服務器運行時。

+0

應用程序在本地運行但部署到服務器錯誤將出現,以解決它。請幫助我 – prabakar

2

有沒有servlet-api.jar是war文件的一部分?請在部署過程中將其刪除,因爲每個Web服務器都有自己的servlet-api實現。所以只能在你的代碼中使用它來編譯目的。

+0

應用程序在本地運行,但部署到服務器錯誤發生。 – prabakar

+0

您是否在兩個位置使用相同的服務器?提取你的war文件並檢查servlet-api jar是否存在於WEB-INF/lib文件夾中。 –

0

根據您發佈的錯誤,正在加載組織/阿帕奇/ JSP/redirect_jsp類加載器和類加載器
組織/阿帕奇/碧玉/運行/ InstanceManagerFactory,有種類不同的類的對象組織/ apache/tomcat/InstanceManager這意味着你在兩個不同的類加載器中引用一個包含org.apache.tomcat.InstanceManager的jar,並且這些加載器具有委託關係。 Class對象基於其完全限定的類名和它們的加載器是唯一的。

這是一個相當不錯的article to read關於這種類型的錯誤。

您需要了解如何兩次加載該課程並修改設置,以便只加載一次。

0

正如前面的文章中提到的,它應該是由於您的項目中存在衝突的庫(jsp-api,servlet-api,el-api等),您需要排除這些庫。

如果您使用的是spring-boot,則需要在生成要在tomcat中部署的war時排除tomcat庫。

對於離。

<exclusion> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-tomcat</artifactId> 
</exclusion> 
<exclusion> 
    <groupId>org.apache.tomcat.embed</groupId> 
    <artifactId>tomcat-embed-el</artifactId> 
</exclusion> 
相關問題