SpringBoot项目报错处理

作者:陆金龙    发表时间:2022-12-01 23:25   

关键词:Unable to start embedded container  Error creating bean with name tomcatEmbeddedServletContainerFactory  

1.项目启动报错

Unable to start embedded container,Error creating bean with name tomcatEmbeddedServletContainerFactory

代码没有问题,运行Run As  - Java Application, 启动报错:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in clas

解决方案:

对所有项目执行Maven的Update Project,解决。如下图:

2.slf4j组件报错

Failure to transfer org.slf4j:slf4j-api:jar:1.7.25 from 

上次下载失败引起的报错。

删掉这些文件,执行 项目右键->Maven-> Update Projects重新下载。

3.aspectj组件报错

Failure to transfer org.aspectj:aspectjweaver:jar:1.8.13 from

原因和处理方案同上。

4.Eureka报错

com.netflix.discovery.shared.transport.TransportException: Retry limit reached; giving up on completing the request

这里使用了域名,在hosts文件中配置域名映射到127.0.0.1即可。

5.Access denied for user 'root'@

Access denied for user 'root'@'116.1.6.12' (using password: YES)

root用户没有远程访问数据库的权限。

解决方案:改为使用非root用户连接数据库,即可。

6.SilentExitExceptionHandler

以debug方式启动springboot之后,都会在SilentExitExceptionHandler类中的throw new SilentExitException()处终止,虽然不影响程序运行。

解决办法 :window->preferences ->java->debug 取消“suspend execution on uncaught exceptions”选项即可。

7.Source folder is not a Java project

Eclipse建立的默认工程并不是Java,所以在新建类时会提示Source folder is not a Java project的错误,导致不能下一步操作;

解决方案:

单击工程鼠标右键->Properties;

在弹出的Properties配置窗口左则选择Project Facets,单击右则的 Convert to faceted form...

在右则的列表选择Java,然后单击Apply and Close;

8.SpringBootApplication cannot be resolved to a type

引包:import org.springframework.boot.autoconfigure.SpringBootApplication;

The import org.springframework cannot be resolved

错误原因是因为springboot的包冲突了所致。需要删掉 repository\org\springframework\boot 目录下的spring-boot-autoconfigure 文件夹,然后在工程中maven -> update project

9.不显示Maven Dependencies依赖

editor does not contain a main type

因为子工程的依赖配置外部多了一个节点dependencyManagement,导致不显示maven依赖,且引用不了SpringBootApplication,去掉它。

这个节点只应该在父工程中使用。

10.程序启动失败,端口占用

The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.

8080 端口被占用,换个端口。

11.FreeMarker未生效

org.apache.ibatis.executor.ExecutorException: No constructor found in com.klfront.klcms.entity.Dept matching [java.lang.Long, java.lang.String, java.lang.String]

为Dept 添加默认构造函数。

12.No converter found for return value of type: class com.klfront.klcms.entity.Dept

是jsckson-core\jsckson-databind\jsckson-annotations的那三个包没有下载完整,因为我一开始是用maven中央仓库http://mvnrepository.com/里面下载的,而限制的原因没有下载完整,后来在apache-maven-*.*.*/conf/settings.xml文件里面添加了阿里云镜像仓库的依赖。

原因:这是因为springmvc默认是没有对象转换成json的转换器的,添加jackson依赖。

 <dependency>

            <groupId>com.fasterxml.jackson.core</groupId>

            <artifactId>jackson-core</artifactId>

            <version>2.5.4</version>

 </dependency>

 <dependency>

            <groupId>com.fasterxml.jackson.core</groupId>

            <artifactId>jackson-databind</artifactId>

            <version>2.5.4</version>

</dependency>