目录

1. RequiredArgsConstructor空指针错误

2.TestRestTemplate注入时异常NoSuchBeanDefinitionException

3. 错误信息:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

4.factory-bean reference points back to the same bean definition


1. RequiredArgsConstructor空指针错误

定义了一个类,用以下注解修饰

@Service("ABC")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))

拿掉@RequiredArgsConstructor(onConstructor = @__(@Autowired))这个注解之后报空指针错

ABC这个bean没有注入进去

@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsContructor。是Lombok插件三种生成不同构造方法的注解,来完成项目中不同构造方法的需求。

@RequiredArgsConstructor的作用是: 会生成一个包含常量,和标识了NotNull的变量的构造方法。生成的构造方法是私有的private

2.TestRestTemplate注入时异常NoSuchBeanDefinitionException

错误信息如下:

Unsatisfied dependency expressed through field 'testRestTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.test.web.client.TestRestTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方式:在spring test的启动类里面将启动类的注解的SpringBootTest注解改为如下即可:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

3. 错误信息:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

在自己新建一个maven项目之后,引入了spring的相关依赖,随即在java包当中写了一个spring boot的启动类,但是在启动时报了如下错误:

** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.2019-03-13 22:23:48.872  WARN 7753 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [Application]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurer.class] cannot be opened because it does not exist
2019-03-13 22:23:48.885  INFO 7753 --- [           main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-13 22:23:48.895 ERROR 7753 --- [           main] o.s.boot.SpringApplication               : Application run failedorg.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [Application]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurer.class] cannot be opened because it does not existat org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at Application.main(Application.java:7) [classes/:na]
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurer.class] cannot be opened because it does not existat org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:88) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:75) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:734) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getInterfaces(ConfigurationClassParser.java:963) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.processInterfaces(ConfigurationClassParser.java:376) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:324) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:194) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:202) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:170) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]... 13 common frames omitted

这个错误提示的是WebSocketMessageBrokerConfigurer相关的错误,我非常纳闷,我什么逻辑都没写怎么会报这个错了,又注意到了一条警告信息:ApplicationConetext没有启动。猜测应该是springboot自动配置相关。于是上google上一搜,发现了原因是因为spring boot的启动类必须放在某一个具体的包下面。

这是错误的方式:

这才是正确的方式:

进一步分析原因,熟悉spring boot自动装配原理的朋友应该知道spring boot的自动配置是基于注解@SpringbootApplication的,而这个注解是以它所修饰的类也就是这里的Application类,所在的包的位置去决定scan扫描哪些包的。因此当Application不在一个包下面时,我们的component scan就没有生效而我们自己定义的配置也就不会生效。

更多的信息可以参考stackover flow上的这个问题:链接。

4.factory-bean reference points back to the same bean definition

源代码定义如下 :

@Configuration
public class TargetDataSource {@Bean("targetDataSource")@ConfigurationProperties(prefix="spring.datasource.target")public DataSource dataSource() {return DataSourceBuilder.create().build();}}

在运行的时候报错:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'targetDataSource' defined in class path resource [com/sap/ngom/datamigration/configuration/TargetDataSource.class]: factory-bean reference points back to the same bean definitionat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:705)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:669)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:637)at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489)at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:420)at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:390)at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:222)at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1276)at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815)at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721)

原因在于这里的Class也是一个bean,datasource也是一个bean,而且他们的名字一样,在修改名字不一样之后,错误消失。

5.Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

启动spring boot应用程序时报错如下

***************************
APPLICATION FAILED TO START
***************************Description:Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:Property: driverclassnameValue: org.h2.DriverOrigin: "driverClassName" from property source "source"Reason: Unable to set value for property driver-class-nameAction:

原因在于代码中定义了h2数据库的bean,但是却缺少相关的maven依赖。去掉之后错误消失。

[Bug] Spring相关bug收集相关推荐

  1. 【RA6M4学习RT-Thread相关bug答疑】

    [RA6M4学习RT-Thread相关bug答疑] 相关教程: [实验1:RT-Thread环境搭建+IIC光线传感器实验] [实验2:ADC电位计实验] [实验3:RW007联网实验] [实验4:M ...

  2. 黑马旅游网站之搜索查询的相关bug

    最近在做毕业设计,我用springboot重新写了一下黑马旅游网,解决了搜索功能的相关bug,也发现了一个目前解释不了的问题. 问题背景:在对旅游线路进行分页展示的时候,有三种操作:1.点击线路分类c ...

  3. fastclick解析与ios11.3相关bug原因分析

    最近发现升级到ios11.3之后,输入框点击变得不灵敏,第二次点击页面中的输入框需要长按一会才能正常唤起键盘输入.排查后,怀疑是fastclick出现了问题,上github看了issues,果不其然很 ...

  4. CKFinder3.5.1免费和整合springboot等相关bug修复

    CKFinder3.5.1免费和整合springboot等相关bug修复 前言 项目本身bug修复 ■ 流异常 ■ 整合springboot相关bug 免费过程 ■ 代码可读化 ① 初步整理 ② 大致 ...

  5. 如何区分前端BUG和后端BUG

    1.如何区分前端和后端 通俗讲,用户看到的部分都叫前端. 而用户看不到的部分可以统称为后端. 2.前端和后端的呈现形式 前端的呈现形式有web端.移动端(ios.安卓).小程序等. 后端系统一般只有一 ...

  6. 软件测试(基础)· 软件测试的生命周期 · 如何描述一个 Bug · Bug 的级别 · Bug 的生命周期 · 争执 · Bug 评审

    一.软件测试的生命周期 软件测试的生命周期 & 软件开发的生命周期 二.如何描述一个 Bug 三.如何定义 Bug 的级别 四.Bug 的生命周期 五.发生争执了怎么办? Bug 评审 一.软 ...

  7. 后端拼接html能做判断吗,怎么判断是前端bug还是后端bug?

    在提bug时,只有明确定位是前端bug还是后端bug,才能正确指派给对应的开发同学,如果经常分不清楚,一直需要开发同学重新指派,不仅浪费了时间,还会被开发同学吐槽,今天就带大家解锁一些区分前后端bug ...

  8. 【判断是前端bug还是后端bug】

    判断是前端bug还是后端bug 一.界面相关,排版错乱,文案错误等问题,大都属于前端bug 1.出现样式的问题基本都是CSS的bug 2.出现文本的问题基本都是html的bug 3.出现交互类的问题基 ...

  9. 软件测试Bug,你是怎么找bug的?bug分析的正确打开方式......

    目录:导读 前言 一. bug详细 二.获取bug具体数据 三.有效的管理bug 四.做好bug分析工作 五.深入bug分析 六.总结 前言 Bug严重级别(Severity,Bug级别):是指因缺陷 ...

最新文章

  1. 《游戏设计师修炼之道:数据驱动的游戏设计》一2.8小结
  2. matlab中的containers.Map()
  3. 在Spring Boot中加载初始化数据
  4. 免费当天澳洲运营商全天下载量达1841TB
  5. .NET Core中使用Razor模板引擎
  6. java实现人脸识别源码【含测试效果图】——Service层(IUserService)
  7. C#中的Switch语句【C#】
  8. debian 重复执行sh_debian 脚本启动方式
  9. 详解JavaScript变量类型判断及domReady原理 写得很好
  10. 办公自动化-演练-统计日报的演练-0223
  11. modelsim和matlab联合仿真,Modelsim与Matlab联合仿真
  12. Vector Packet Processor(VPP) - 层二层三转发图谱
  13. android蓝牙在有效范围内自动连接,android – 如何在范围内找到可用的蓝牙设备?...
  14. 软件工程第三次作业(最大子段和)
  15. 阶段3 3.SpringMVC·_04.SpringMVC返回值类型及响应数据类型_7 响应json数据之发送ajax的请求...
  16. 数学建模比赛需要那些c语言的知识,数学建模需要掌握哪些编程语言和技术
  17. 麦肯锡:数字化转型四步法
  18. kmplayer播放flv文件不正常(屏幕绿色滤镜或者很模糊)怎么办?
  19. C++实现的windows系统下的WIFI管理
  20. 怎样隐藏Word内容?这样操作只需30秒!

热门文章

  1. Cannot checkout from svn: svn: E155000: ‘XXX‘ is alrea
  2. Linux——万字总结用户与组相关知识!建议收藏!
  3. recyclerview简单使用
  4. nape.geom.MarchingSquares
  5. Android高级工程师面试实战,赶快收藏备战金九银十!
  6. javax.servlet-api 简介、中文文档、中英对照文档 下载
  7. Julia 数学运算和初等函数
  8. TreeGrid插件简练了解使用
  9. 字节跳动社招全岗位研发面经(已拿offer)
  10. 如何将时间序列分解为周期序列和趋势序列的和?