springboot的常見問題錯誤


一:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name

2019-03-08 16:07:14.132 ERROR 9936 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@2f7c2f4f] to prepare test instance [com.example.demo.DemoApplicationTests@5491f68b]

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.example.demo.DemoApplicationTests': Unsatisfied dependency expressed through field 'person'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.beans.Person' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation

是因為測試的application類訪問不到autowired注解的屬性的對象所在的包。

application只能訪問同一包下的文件,或者是同一包下的子文件

 

 二:

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

是因為application和junit所在的包名不一樣導致

三:是因為yml文件中存在tab鍵等yml文件有問題

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM