自动发布的问题/找不到bean

时间:2015-11-06 00:44:50

标签: java spring spring-mvc spring-security spring-boot

我正在尝试实现Spring Boot并设置我的用户服务。我无法找到无法找到UserService bean的错误。任何建议或方向将不胜感激。 UserController的 @RestController public class UserController {     private final IUserService userService;     @注入     public UserController(final IUserService userService){         this.userService = userService;     }     @RequestMapping(value =" / user",method = RequestMethod.POST)     public FBUser createUser(@RequestBody @Valid final FBUser fBUser){         return userService.save(fBUser);     } } IUserService 公共接口IUserService {     FBUser save(FBUser fBUser); } UserService 公共类UserService实现IUserService {     私人最终IUserRepository存储库;     @注入     public UserService(最终IUserRepository存储库){          this.repository = repository;     }     @覆盖     @Transactional     public FBUser save(final FBUser fBUser){         return repository.save(fBUser);     } } IUserRepository 公共接口IUserRepository扩展了JpaRepository< FBUser,Long> { } 错误 线程" main"中的例外情况org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为' userController'的bean时出错在文件[/Users/christopher/workspace/FeedAndBedding/target/classes/com/creativefuhsion/controllers/UserController.class]中定义:通过构造函数参数表达的不满意的依赖关系,类型为[com.creativefuhsion.services.impls.UserService]的索引0 ::没有找到[com.creativefuhsion.services.impls.UserService]类型的限定bean用于依赖:预期至少有1个bean可以作为此依赖项的autowire候选者。依赖注释:{};嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到类型为[com.creativefuhsion.services.impls.UserService]的限定bean依赖:预期至少有1个bean符合此依赖关系的autowire候选者。依赖注释:{}     在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)     在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1137)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1040)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)     at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)     在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:759)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117)     在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689)     在org.springframework.boot.SpringApplication.run(SpringApplication.java:321)     在org.springframework.boot.SpringApplication.run(SpringApplication.java:969)     在org.springframework.boot.SpringApplication.run(SpringApplication.java:958)     at com.creativefuhsion.FeedAndBeddingApplication.main(FeedAndBeddingApplication.java:16)  由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到类型[com.creativefuhsion.services.impls.UserService]的限定bean用于依赖:预期至少有1个bean符合此依赖关系的autowire候选者。依赖注释:{}     at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)     at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)     在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)     在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)     在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ......还有18个

1 个答案:

答案 0 :(得分:6)

使用@Service注释您的用户服务:

@Service
public class UserService implements IUserService {

否则Spring会在扫描要注入的内容时找不到它。