maven打包spring出现的多命名空间问题

在IDEA里能正常运行,用maven打成jar包后运行出现异常:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [applicationContext.xml]

applicationContext.xml内容如下


    
        
        
        
        
    
    
    
        
        
        
        
        

    
    
    
        
        
    
    
        
    
    

xml出现了 bean和context两个命名空间,网上说是由于多命名空间覆盖而没有合并导致的。

更改pom.xml中打包plugin如下解决:


    org.apache.maven.plugins
    maven-shade-plugin
    2.4.1
    
        
            package
            
                shade
            
            
                
                    
                        com.***.***.Application
                    
                    
                        META-INF/spring.handlers
                    
                    
                        META-INF/spring.schemas
                    
                
            
        
    

下面开始讲最重要的事:

改plugin的时候一定要把之前有问题的plugin删掉!

改plugin的时候一定要把之前有问题的plugin删掉!

改plugin的时候一定要把之前有问题的plugin删掉!

我就是没有把有问题的plugin删掉,而是在后面追加了这个,导致一直出问题........

看了下面这篇文章才最终解决这个问题,文章里对maven的打包讲的也很全

https://blog.csdn.net/silentwolfyh/article/details/81506977

你可能感兴趣的:(杂谈)