IDEA代码编辑器发展很快,现在很多都从Eclipse转到IDEA来了,我就是其中一个,感觉IDEA黑色的主题我感觉很不错

好了,下面切入正题
Eclipse启动Spring boot没有报错,为啥IDEA启动就报错,报错提示如下:
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
发现是找不到容器用来启动,可是我明明在pom文件中配置了
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
<scope>provided</scope>
</dependency>
为啥就找不到undertow的容器,然而Eclipse就可以?
Eclipse启动的时候找到了undertow的jar。maven的scope为provided时本来不会自动找到undertow的jar。估计是Eclipse做了调整。
这样就有
解决方法一,注释掉<scope>provided</scope>,重启,验证解决问题
有后续影响,如果一不小心提交了这个,就会导致测试环境有可能出现,因为笔者公司测试环境有单独的容器
法二:在解决方法一的基础上,想到启动不了,就是启动的时候少了这些依赖包,那我就手动加上这些依赖包,那现在我们来看看某个项目的依赖包,如图File->Project Structure
发现是少了容器的jar包。
现在我们建立一个IDEA的Global libraries,如图,展示一个我建好的
使用这个library。
重启就好
遗留问题,spring-boot-starter-undertow:1.5.10.RELEASE版本这个版本启动还是报错,发现少了nio包,这个应该是maven依赖没有加入,那我们手动添加一下,选择maven库的org/jboss/xnio/xnio-nio/3.3.8.Final/xnio-nio-3.3.8.Final.jar,如图

- 大小: 61.1 KB

- 大小: 82.9 KB

- 大小: 311.3 KB

- 大小: 88.9 KB
分享到:
评论