Maven+Spring Boot 整合时一些报错整理

1.在进行单元测试时遇到一些问题
首先是使用SpringApplicationConfiguration注解报错
原因是该方法已失效
正确应使用SpringBootTest注解

按照spring-boot官网上的依赖下载jar报错:
Archive for required library: 'C:/Users/Administrator/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.16/tomcat-embed-core-8.5.16.jar' in project 'chapter3-1-1' cannot be read or is not a valid ZIP file chapter3-1-1 Build path Build Path Problem
Description Resource Path Location Type
Archive for required library:
'C:/Users/Administrator/.m2/repository/org/
springframework/boot/spring-boot-test/1.4.2.RELEASE/spring-boot-test-1.4.2.RELEASE.jar'
in project 'chapter3-1-1'
cannot be read or is not a valid ZIP file
chapter3-1-1
Build path Build Path Problem

解决方法:找到该目录下的文件,删除,然后使用maven clean,maven update


2.今天在使用maven导入springboot工程时,有些注解使用不上,比如:@SpringBootApplication注解失效,报错如下:
Description Resource Path Location Type
springBootApplication cannot be resolved to a type Application.java /chapter3-1-1/src/main/java/com/spring line 5 Java Problem

解决方法:
Go to your maven repository directory For windows on below path C:\Users\YourUser\.m2\repository\org\springframework\boot Then delete spring-boot-autoconfigure folder.

还遇到如下报错:
Description Resource Path Location Type
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.core.NestedRuntimeException. Fix the build path then try building this project chapter3-1-1 Unknown Java Problem

解决方案:找到org.springframework.core.NestedRuntimeException在本地仓库中的位置,次问题出在spring-core的maven依赖中,删除其中的所以文件
再maven update


问题:启动springboot时自动关闭,报错如下
2017-09-07 23:32:58.893 INFO 4004 --- [ main] com.spring.Application : Starting Application on 2012-20130927RW with PID 4004 (F:\eclipseMars\workspace\chapter3-1-1\target\classes started by Administrator in F:\eclipseMars\workspace\chapter3-1-1)
2017-09-07 23:32:58.900 INFO 4004 --- [ main] com.spring.Application : No active profile set, falling back to default profiles: default
2017-09-07 23:32:58.980 INFO 4004 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1a247d1: startup date [Thu Sep 07 23:32:58 CST 2017]; root of context hierarchy
2017-09-07 23:33:01.169 INFO 4004 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-09-07 23:33:01.184 INFO 4004 --- [ main] com.spring.Application : Started Application in 2.61 seconds (JVM running for 3.341)
2017-09-07 23:33:01.185 INFO 4004 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@1a247d1: startup date [Thu Sep 07 23:32:58 CST 2017]; root of context hierarchy
2017-09-07 23:33:01.187 INFO 4004 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

原因是:
org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser自動檢測,jdk版本檢測時需要jre1.5以上版本,但是JdkVersion只檢查到了1.7,jre1.8 時不匹配任何jdk, 修正如下,問題解决

上面的解决方案是我在网上找到的,但是原因还是jar包的问题,我没有深究问题到底出在哪个包,索性一次性把.m2/repository/org下的所有依赖全部删除,然后maven update,问题解决

 

转载于:https://www.cnblogs.com/lenghui/p/7498957.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值