“org.springframework.web.context.support.ServletContextAwareProcessor: method <init>()V not found”问题

问题:

        Spring boot应用突然出现启动不了,报错:

java.lang.NoSuchMethodError: org.springframework.web.context.support.ServletContextAwareProcessor: method <init>()V not found
	at org.springframework.boot.context.embedded.WebApplicationContextServletContextAwareProcessor.<init>(WebApplicationContextServletContextAwareProcessor.java:40)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.postProcessBeanFactory(EmbeddedWebApplicationContext.java:114)
	at org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext.postProcessBeanFactory(AnnotationConfigEmbeddedWebApplicationContext.java:181)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
	at com.nariit.JxxApplication.main(JxdApplication.java:25)

而之前都运行的好好的。中间依赖应用包有重新编译,但编译正常。

分析:

        经人提醒,发现项目依赖spring包冲突。在Eclipse中通过Ctrl + Shift + T,查找“ServletContextAwareProcessor”类,找到spring-1.2.6.jar 与spring-web-4.3.6-RELEASE.jar 2个包中都含有该类,显然spring-web-4.3.6-RELEASE.jar才是我们真正想要的,那就要想办法排除掉不想要的spring.jar包。

解决:

      因为spring-1.2.6.jar 与spring-web-4.3.6-RELEASE.jar均含有ServletContextAwareProcessor类,可以推知应用的依赖包中直接或间接引用了该spring-1.2.6。那如何找到引用了“spring-1.2.6.jar”的jar包呢?

       正确的做法是使用Eclipse pom编辑器的"dependency hierarchy"功能,从右侧列表中点“spring:1.2.6”,在左侧引用树中找到引用它的jar包,假定找到引用包名为“bbb-framework:1.2.2”。接着,在当前应用的pom.xml文件中,找到bbb-framework依赖,排除掉其引用的spring包。

        在pom.xml中使用exclusion排除配置方式:

           <exclusions>
                <exclusion>
                     <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
            </exclusions>   

        加上排除代码后效果如图:

                <dependency>
			<groupId>com.a.bbb</groupId>
			<artifactId>bbb-framework</artifactId>
			<version>1.2.2</version>	
 			<exclusions>
				<exclusion>
					 <groupId>org.springframework</groupId>
					<artifactId>spring</artifactId>
				</exclusion>
			</exclusions>			
		</dependency>

然后保存pom.xml,重新使用maven编译、运行,问题解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值