亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

'com.example.demo.GirlRepository' that could not be found.GirlRepository(已解決)

Description:

Field girlRepository in com.example.demo.GirlController required a bean of type 'com.example.demo.GirlRepository' that could not be found.


Action:

Consider defining a bean of type 'com.example.demo.GirlRepository' in your configuration.


GirlRepository和GirlApplication都在同一個包下面的

http://img1.sycdn.imooc.com//592d260b00016b0204400258.jpg

已解決

正在回答

10 回答

https://img1.sycdn.imooc.com//5b3a31d800010b4e06260172.jpg大兄弟,幫我看下,我用的是這個jpa但是為什么還是注入失敗呢?

0 回復 有任何疑惑可以回復我~
#1

深藍d

我和你一樣,你知道怎么解決了嗎
2019-05-17 回復 有任何疑惑可以回復我~

還有一種可能,少寫了

public?class?GirlService?{

上面的注解@Service

0 回復 有任何疑惑可以回復我~
  1. 你把運行的application類放到最基本的包里,比如:com.imooc 這個包下!

0 回復 有任何疑惑可以回復我~

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@13c10b87: startup date [Mon Aug 21 22:25:23 CST 2017]; root of context hierarchy

at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:556) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]


2017-08-21 22:25:24.528 ERROR 46202 --- [ ? ? ? ? ? main] o.s.b.f.s.DefaultListableBeanFactory ? ? : Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception


java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@13c10b87: startup date [Mon Aug 21 22:25:23 CST 2017]; root of context hierarchy

at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:556) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]

at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]

我包這個錯不知道是啥問題

0 回復 有任何疑惑可以回復我~

這個問題我也存在 但是把所有類放到一個包下面就好了


0 回復 有任何疑惑可以回復我~
#1

qq_Weakmindedyo_0

@SpringBootApplication 這個注解的類要放在最外圍的包里,一遍能管理到其他 controller
2017-09-22 回復 有任何疑惑可以回復我~
#2

慕絲6569890 回復 qq_Weakmindedyo_0

可以留下聯系方式嗎
2017-09-26 回復 有任何疑惑可以回復我~

復制的時候 多了這個<scope>test</scope>在 pom中

0 回復 有任何疑惑可以回復我~

我跟你的錯誤一樣,但是用了import org.springframework.data.jpa.repository.JpaRepository;還是沒解決/(ㄒoㄒ)/~~還可能是什么原因嗎

0 回復 有任何疑惑可以回復我~
#1

未卜先知 提問者

jap在maven中注意要用spring-boot start那個,不要用spring data下的 我是在寫代碼的時候直接用工具導入的,結果工具導入的依賴是spring data的jpa不是spring boot的jpa
2017-06-14 回復 有任何疑惑可以回復我~
#2

glwindy 回復 未卜先知 提問者

灰常感謝
2017-06-15 回復 有任何疑惑可以回復我~
#3

qq_別人家的小明_0

那個,我還是沒搞懂,我導入的是 spring-boot-starter-data-jpa,結果還是報的這個錯誤。。。
2018-01-04 回復 有任何疑惑可以回復我~

是的,是要注入GirlRepository,和GirlProperties沒關系,要不你對比下我的,我能執行?;蛘吣愕拇aidea有提示錯誤嗎?

package com.girl.repository;

import com.girl.domain.Girl;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
* Created by zouzhi on 2017/5/30.
*/
public interface GirlRepository extends JpaRepository<Girl,Integer> {
? ?public List<Girl> findByAge(Integer age);
}



package com.girl.controller;

import com.girl.domain.Girl;
import com.girl.repository.GirlRepository;
import com.girl.service.GirlService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* Created by zouzhi on 2017/5/30.
*/
@RestController
public class GirlController {


? ?private final static Logger logger = LoggerFactory.getLogger(GirlController.class);

? ?@Autowired
? ?private GirlRepository girlRepository;

? ?@Autowired
? ?private GirlService girlService;

? ?@GetMapping(value = "/girls")
? ?public List<Girl> girlList(){
? ? ? ?//System.out.println("girlList()");
? ? ? ?logger.info("girlList()");
? ? ? ?return ?girlRepository.findAll();
? ?}

? ?@PostMapping(value = "/girls")
? ?public Girl add(@Valid Girl girl,
? ? ? ? ? ? ? ? ? ?BindingResult bindingResult){
? ? ? ?if(bindingResult.hasErrors()){
? ? ? ? ? ?//System.out.println(bindingResult.getFieldError().getDefaultMessage());
? ? ? ? ? ?logger.info(bindingResult.getFieldError().getDefaultMessage());
? ? ? ? ? ?return null;
? ? ? ?}
? ? ? ?return girlRepository.save(girl);

? ?}
? /* public Girl add(@RequestParam("cupSize")String cupSize,
? ? ? ? ? ? ? ? ? ? ?@RequestParam("age")Integer age){
? ? ? ?Girl girl = new Girl();
? ? ? ?girl.setAge(age);
? ? ? ?girl.setCupSize(cupSize);

? ? ? ?return girlRepository.save(girl);

? ?}*/

? ?@GetMapping(value = "/girls/{id}")
? ?public Girl get(@PathVariable("id")Integer id){
? ? ? ?return girlRepository.findOne(id);
? ?}

? ?@PutMapping(value = "/girls/{id}")
? ?public Girl update(@PathVariable("id")Integer id,
? ? ? ? ? ? ? ? ? ? ? @RequestParam("cupSize")String cupSize,
? ? ? ? ? ? ? ? ? ? ? @RequestParam("age")Integer age){
? ? ? ?Girl girl = new Girl();
? ? ? ?girl.setId(id);
? ? ? ?girl.setCupSize(cupSize);
? ? ? ?girl.setAge(age);

? ? ? ?return girlRepository.save(girl);

? ?}

? ?@DeleteMapping(value = "/girls/{id}")
? ?public void delete(@PathVariable("id")Integer id){
? ? ? ?girlRepository.delete(id);
? ?}

? ?@GetMapping(value = "girls/age/{age}")
? ?public List<Girl> girlListByAge(@PathVariable("age")Integer age){
? ? ? ?return ?girlRepository.findByAge(age);
? ?}

? ?@PostMapping(value = "/girls/two")
? ?public void girlTwo(){
? ? ? ?girlService.insertTwo();
? ?}

}

0 回復 有任何疑惑可以回復我~
#1

未卜先知 提問者

解決了,寫的時候按照idea提示加了Spring下的jpa,不是Spring boot下的jpa,所以找不到 import org.springframework.data.jpa.repository.JpaRepository; 這個導入是一模一樣的
2017-05-30 回復 有任何疑惑可以回復我~
#2

為伊塵心 回復 未卜先知 提問者

我也沒想到這個
2017-05-30 回復 有任何疑惑可以回復我~
#3

我愛lyf 回復 未卜先知 提問者

我可以問一下,這是什么意思嗎?我也出現了同樣的問題,百度了一下午,不知道該怎么解決~
2017-10-20 回復 有任何疑惑可以回復我~
#4

深藍d 回復 未卜先知 提問者

所以是怎么改的呢
2019-05-16 回復 有任何疑惑可以回復我~
查看1條回復

@Component
@ConfigurationProperties(prefix = "girl")
public class GirlProperties {


黑體文字加了嗎?

回復你不能加黑體,你看這個回復 ?黑體部分


0 回復 有任何疑惑可以回復我~
#1

未卜先知 提問者

GirlProperties這個類前面肯定是加了@Component的 但是要注入的是GirlRepository,不是GirlProperties,這兩者沒關系啊
2017-05-30 回復 有任何疑惑可以回復我~

@RestController
public class GirlController {

? ?@Autowired
? ?private ?GirlRepository girlRepository;


注意上面加粗的文字

0 回復 有任何疑惑可以回復我~
#1

未卜先知 提問者

@RestController public class GirlController { @Autowired private GirlRepository girlRepository; @GetMapping(value = "/girls") public List<Girl> girlList(){ return girlRepository.findAll(); } } 這個 按道理 我都寫了啊
2017-05-30 回復 有任何疑惑可以回復我~
#2

為伊塵心 回復 未卜先知 提問者

@Component @ConfigurationProperties(prefix = "girl") public class GirlProperties { 黑體文字加了嗎?
2017-05-30 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
2小時學會Spring Boot
  • 參與學習       151526    人
  • 解答問題       1132    個

Spring Boot入門視頻教程,你將學會使用Spring Boot快速構建應用程序

進入課程

'com.example.demo.GirlRepository' that could not be found.GirlRepository(已解決)

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號