'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都在同一個(gè)包下面的
已解決
2018-07-02
2018-05-08
還有一種可能,少寫(xiě)了
上面的注解@Service
2018-01-27
你把運(yùn)行的application類(lèi)放到最基本的包里,比如:com.imooc 這個(gè)包下!
2017-08-21
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]
我包這個(gè)錯(cuò)不知道是啥問(wèn)題
2017-08-15
這個(gè)問(wèn)題我也存在 但是把所有類(lèi)放到一個(gè)包下面就好了
2017-07-16
復(fù)制的時(shí)候 多了這個(gè)<scope>test</scope>在 pom中
2017-06-09
我跟你的錯(cuò)誤一樣,但是用了import org.springframework.data.jpa.repository.JpaRepository;還是沒(méi)解決/(ㄒoㄒ)/~~還可能是什么原因嗎
2017-05-30
是的,是要注入GirlRepository,和GirlProperties沒(méi)關(guān)系,要不你對(duì)比下我的,我能執(zhí)行?;蛘吣愕拇aidea有提示錯(cuò)誤嗎?
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();
? ?}
}
2017-05-30
@Component
@ConfigurationProperties(prefix = "girl")
public class GirlProperties {
黑體文字加了嗎?
回復(fù)你不能加黑體,你看這個(gè)回復(fù) ?黑體部分
2017-05-30
@RestController
public class GirlController {
? ?@Autowired
? ?private ?GirlRepository girlRepository;
注意上面加粗的文字