今天在做项目的时候,来了个奇怪的异常,具体异常如下:
Java代码
java.lang.LinkageError: loader constraint violation:    
 
google了一会发现原来是jboss的类加载器的问题。因为同一个类被不同的类加载器所加载导致的,所以要按照一下步骤来修改几个配置文件就OK了。

First, edit the conf/jboss-service.xml file and set the NamingService CallByValue to true:
Java代码
<mbean code="org.jboss.naming.NamingService"    
             name="jboss:service=Naming">        
        <!-- The call by value mode. true if all lookups are unmarshalled using        
            the caller's TCL, false if in VM lookups return the value by reference.        
        -->        
        <attribute name="CallByValue">true</attribute>        
    
            ...        
</mbean>    
 
Second, edit the deploy/ear-deployer.xml file and set the Isolated and CallByValue attributes to true:
Java代码
<server>        
     <!-- EAR deployer, remove if you are not using ear deployments -->        
     <mbean code="org.jboss.deployment.EARDeployer"    
            name="jboss.j2ee:service=EARDeployer">        
            <!-- A flag indicating if ear deployments should have their own scoped        
            class loader to isolate their classes from other deployments.        
            -->        
            <attribute name="Isolated">true</attribute>        
            <!-- A flag indicating if the ear components should have in VM call        
            optimization disabled.        
            -->        
            <attribute name="CallByValue">true</attribute>        
     </mbean>        
</server>    
 
Last, edit the deploy/jbossweb-tomcat50.sar/META-INF/jboss-service.xml file and set the Java2ClassLoadingCompliance and UseJBossWebLoader attributes to false:
Java代码
<server>        
    
     <mbean code="org.jboss.web.tomcat.tc5.Tomcat5"    
            name="jboss.web:service=WebServer">        
    
            <!-- Get the flag indicating if the normal Java2 parent first class    
                     loading model should be used over the servlet 2.3 web container first        
                     model.        
            -->        
            <attribute name="Java2ClassLoadingCompliance">false</attribute>        
    
            <attribute name="LenientEjbLink">true</attribute>        
    
            <!-- A flag indicating if the JBoss Loader should be used. This loader        
                     uses a unified class loader as the class loader rather than the tomcat        
                     specific class loader.        
            -->        
            <attribute name="UseJBossWebLoader">false</attribute>        
    
                ...    
 
注意:如果是在jboss-4.2.1.GA下,第三步可以不用改了,默认就是false.