本文共 4282 字,大约阅读时间需要 14 分钟。
作者:朱金灿
来源:
需要使用java实现一个http接口,同事推荐我使用SpringBoot。我使用的是开发环境是eclipse Oxygen.2 Release (4.7.2),jdk 1.8(64位),按照来创建工程项目。开始很顺利,编译通过,等运行时出现了java.lang.IllegalArgumentException: Sources must not be empty的错误,具体如下图:
出错信息如下:
然后我就开始我的折腾之旅了。上网搜了下开始以为了SpringBoot的版本有点低,在pom.xml中将SpringBoot从1.5.2.RELEASE改为1.5.9.RELEASE,然后使用maven更新工程,运行后依然出现一样的问题。再接着准备下载一个SpringBoot的专用开发工具STS,发现这个工具不支持Oxygen.2 Release (4.7.2),然后就去下载Eclipse最新版4.12。现在下来更新插件时发现qiang太厉害了,把maven的官网都堵住了,然后就想到把maven的更新源改为阿里云,具体是新建一个settings.xml,内容如下:
D:\Software\DevTools\m2\repository alimaven aliyun maven http://maven.aliyun.com/nexus/content/groups/public/ central
然后在选择”Window”——”Preferences”进行设置,如下图:
借助这个eclipse的插件更新了,然后再更新工程编译运行,启动项目时报错:
org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
查了一下资料,解决办法是加上@EnableAutoConfiguration注解,具体参考:。
然后再编译运行,出现一个新错误:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: org.apache.catalina.Context.addServletMapping(Ljava/lang/String;Ljava/lang/String;)V
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at com.test.springboot.springboot_first.SpringBootApplicationFirst.main(SpringBootApplicationFirst.java:14) [classes/:na]
Caused by: java.lang.NoSuchMethodError: org.apache.catalina.Context.addServletMapping(Ljava/lang/String;Ljava/lang/String;)V
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.addServletMapping(TomcatEmbeddedServletContainerFactory.java:290) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.addDefaultServlet(TomcatEmbeddedServletContainerFactory.java:270) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.prepareContext(TomcatEmbeddedServletContainerFactory.java:215) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:178) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
... 8 common frames omitted
再将SpringBoot从1.5.2.RELEASE改为1.5.9.RELEASE,依然一样的错误。到网上搜了一条信息:
将SpringBoot从1.5.9.RELEASE再改为2.0.2.RELEASE,然后用maven更新工程,编译运行,这下终于好了。
不过我还有一些疑问:我最新建立的工程在我的一个朋友的机器上是能正常运行的,到底是什么原因造成了这个错误呢?
转载地址:http://ngimb.baihongyu.com/