一.springboot启动异常
1.端口占用
I.报错log
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-06-26 20:48:01.000 ERROR 15332 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
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.
II.问题分析
这类问题在springboot中经常出现,凡是类似的问题一般都是端口被占用了,找出占用端口的PID然后结束进程即可
III.解决
i.打开cmd命令窗口 输入如下指令查看所有端口和PID
netstat -ano
ii.找到对应的端口对应的PID 输入指令找到对应的进程(2个命令都可以用)
tasklist | findstr "7676" 7676指端口对应的PID
taskkill /f /t /im pid pid指端口对应的PID
iii.杀掉该进程 再次启动就OK啦
taskkill /f /t /im java.exe
2. spring的bean同名冲突
I.报错log
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.git.hui.boot.beanorder.Application]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'sameA' for bean class [com.git.hui.boot.beanorder.choose.samename.b.SameA] conflicts with existing, non-compatible bean definition of same name and class [com.git.hui.boot.beanorder.choose.samename.a.SameA]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'sameA' for bean class [com.git.hui.boot.beanorder.choose.samename.b.SameA] conflicts with existing, non-compatible bean definition of same name and class [com.git.hui.boot.beanorder.choose.samename.a.SameA]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:348) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
II.问题分析
bean名称相同冲突
两个实现类上面都只用了@service这个注解,根据映射规则,这两个service都映射为了xxxServiceImpl,发生了冲突
III.解决
i.将其中一个实现类改为不同的名字;
ii.将其中一个注解变更为一个name为非xxxServiceImpl的注解@service(name="aaaa")。
3.springcloud启动失败,maven依赖冲突问题
I.报错log
An attempt was made to call a method that does not exist...
II.问题分析
看了下应该是[maven](https://so.csdn.net/so/search?q=maven&spm=1001.2101.3001.7020)依赖里面 servlet-api冲突导致
用idea里面的插件 Maven Helper ,查看报错的pom文件,对应的Dependency Analyzer 情况;
III.解决
i.在相应的pom文件Dependency Analyzer下,选择All Dependencies as Tree,搜索框内输入冲突的jar名称:servlet-api
ii.右键选择Exculde
iii.刷新maven,查看是否排除依赖成功
4.springboot和springcloud版本不兼容启动失败
I.报错log
II.问题分析
使用springboot2.7.3和springcloud2020.0.5出现的版本不兼容问题
III.解决
方案一:
xxx.yml配置文件中添加不检查版本校验配置
spring:
cloud:
compatibility-verifier:
enabled: false
方案二:
手动降低或升级对应版本
二.数据库报错
1.数据库字段和实体类属性名不一致
I.报错log
###Error querying database. Cause: java.sql.SQLSyntaxErrorException:
Unknown column 'xxx' in 'where clause'
II.问题分析
III.解决
2. mapper和mapper.xml没有映射起来
I.报错log
# Invalid bound statement (not found)
II.问题分析
mapper接口和mapper.xml文件没有映射起来
III.解决
方案一:检查 mapper.xml中的namespace和实际的mapper文件是否一致
方案二:检查mapper接口中的方法名和mapper.xml中的id标签是否一致
方案三:Mapper.xml没有构建进去 打开target看看对应的Mapper.xml文件在不在,如果不在,点击右边的maven,clean之后Run
方案四: 配置文件导不出来 maven的配置文件默认放在resources目录下,但在这里需要把它放到java目录下,导致配置文件导不出来;需要手动配置资源过滤,让它把java目录下的properties和xml等配置文件的过滤开启,使它们能够被导出,在pom.xml中配置开启过滤
<!--在build中配置resources,来防止我们资源导出失败的问题-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
三.其他问题
1.不同模块之间class类名冲突