失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > spring boot项目IDEA启动报错问题解决

spring boot项目IDEA启动报错问题解决

时间:2020-11-16 05:33:32

相关推荐

spring boot项目IDEA启动报错问题解决

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

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做了调整。

这样就有[color=red][b]解决方法一[/b][/color],注释掉<scope>provided</scope>,重启,验证解决问题

有后续影响,如果一不小心提交了这个,就会导致测试环境有可能出现,因为笔者公司测试环境有单独的容器

[color=red][b]法二:[/b][/color]在解决方法一的基础上,想到启动不了,就是启动的时候少了这些依赖包,那我就手动加上这些依赖包,那现在我们来看看某个项目的依赖包,如图File->Project Structure

[img]/upload/attachment/0130/0487/c4af722a-0c1d-3534-8e5f-df2dddb5e254.png[/img]

发现是少了容器的jar包。

现在我们建立一个IDEA的Global libraries,如图,展示一个我建好的

[img]/upload/attachment/0130/0489/12b5d461-167b-3f2c-8d1f-d19a1baa3ba2.png[/img]

使用这个library。

[img]/upload/attachment/0130/0491/c9879716-2b24-3fd8-b792-4964fc0a5f5b.png[/img]

重启就好

[color=red]遗留问题[/color],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,如图

[img]/upload/attachment/0130/0851/9d49b6c1-55ef-392f-b5ca-c2df2ecf0880.png[/img]

如果觉得《spring boot项目IDEA启动报错问题解决》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。