SpringBoot bean无法注入
2017-08-23 11:04
417 查看
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userP in com.springboot.controller.UserController required a bean of type 'com.springboot.model.UserProperties' that could not be found.
Action:
Consider defining a bean of type 'com.springboot.model.UserProperties' in your configuration.
SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描!
“Application类”是指SpringBoot项目入口类。这个类的位置很关键:
如果Application类所在的包为:
故此Application类应该放在父包com.springboot中,这样就能扫描到com.springboot.controller,service,dao包里的bean了。
Spring
Boot默认会扫描启动类同包以及子包下的注解,那么如何进行改变这种扫描包的方式呢,原理很简单就是:
@ComponentScan注解进行指定要扫描的包以及要扫描的类。
@ComponentScan(basePackages={"com","com.hha"})
APPLICATION FAILED TO START
***************************
Description:
Field userP in com.springboot.controller.UserController required a bean of type 'com.springboot.model.UserProperties' that could not be found.
Action:
Consider defining a bean of type 'com.springboot.model.UserProperties' in your configuration.
SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描!
“Application类”是指SpringBoot项目入口类。这个类的位置很关键:
如果Application类所在的包为:
com.springboot.controller,则只会扫描
com.springboot.controller包及其所有子包,如果service或dao所在包不在
com.springboot.controller及其子包下,则不会被扫描!
故此Application类应该放在父包com.springboot中,这样就能扫描到com.springboot.controller,service,dao包里的bean了。
Spring
Boot默认会扫描启动类同包以及子包下的注解,那么如何进行改变这种扫描包的方式呢,原理很简单就是:
@ComponentScan注解进行指定要扫描的包以及要扫描的类。
@ComponentScan(basePackages={"com","com.hha"})
相关文章推荐
- 解决spring-boot 中 bean无法注入的问题
- 解决Spring boot使用Quartz时Job中无法注入Bean 空指针异常问题
- SpringBoot拦截器中Bean无法注入(转)
- SpringBoot中拦截器无法注入Bean的解决办法
- 关于spring boot无法自动注入bean问题解决方案
- spring boot LoginInterceptor(登录拦截器)无法注入bean
- 解决spring boot websocket无法注入bean的问题
- SpringBoot bean无法注入的问题
- 解决spring boot websocket无法注入bean的问题
- hessian 在spring中的使用 (bean 如 Dao无法注入的问题)
- springboot+jpa+mysql实现增加数据报错,无法创建controller,无法注入jpa接口
- spring容器无法注入service(No qualifying bean of type)
- [Spring Boot实战系列] - No.4 Spring boot 中如何在Utils类中使用@Autowired注入bean
- Spring+Quartz 定时任务无法自动注入bean的问题
- spring+quartz实现定时任务遇到问题总结(bean无法注入)
- 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案
- spring boot 中@Autowired注解无法自动注入的错误
- spring boot获取注入的实例bean
- 解决Spring+Quartz无法自动注入bean问题
- spring boot 拦截器中无法注入serivce