【问题标题】:Java Consider defining a bean of type in your configuration exception when add mongoDB supportJava 考虑在添加 mongoDB 支持时在配置异常中定义类型的 bean
【发布时间】:2017-08-27 03:22:08
【问题描述】:

我有一个非常简单的 Java Springboot 项目连接到数据库。不过,我想要一个 mongoDB 连接,我也可以使用 mongoDB。

我阅读了很多文档,但我无法让它发挥作用。我的提交代码是:

https://github.com/GuoJing/spb/commit/20c04ce38d43bb0ba229d0d3577fdccbd571062e

如果添加@AutoWired 注解,应用程序将无法启动。我觉得应该和官方文档一样。

在 src/main/java/controller/UserController.java

@Autowired
private UserPropsRepository userPropsRepository;

这是我的项目,有人可以帮助我吗?

https://github.com/GuoJing/spb

我的例外是:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field userPropsRepository in controller.UserController required a bean of type 'repository.UserPropsRepository' that could not be found.


Action:

Consider defining a bean of type 'repository.UserPropsRepository' in your configuration.

【问题讨论】:

  • 你得到了什么例外。
  • @RajithPemabandu *************************** 应用程序无法启动 ********* ****************** 描述:controller.UserController 中的字段 userPropsRepository 需要找不到类型为“repository.UserPropsRepository”的 bean。行动:考虑在你的配置中定义一个“repository.UserPropsRepository”类型的bean。
  • 你考虑过我的回答吗?

标签: java spring mongodb spring-boot


【解决方案1】:
  • 我将 Spring Boot 版本更改为 2.1.1.RELEASE,问题已解决。
  • 清除.mvn 文件夹并重建我的项目,问题是 已解决。

【讨论】:

    【解决方案2】:

    问题解决了。

    1. 更改我的项目结构,将根 Package 和 Model 和 Dao ... 移至 com.example.model ...
    2. 将 Application.java 移至根目录,以便自动扫描组件

    涉及到同样的问题和解决方案。

    'Field required a bean of type that could not be found.' error spring restful API using mongodb

    【讨论】:

      【解决方案3】:

      假设您在 UserPropsRepository 接口中缺少 @Repository 注释。

         @repository("userPropsRepository")
         public interface UserPropsRepository extends MongoRepository<UserProps, String> {
          UserProps findOne(String id);
          UserProps save(UserProps props);
          UserProps update(UserProps props);
          void delete(UserProps props);
      }
      

      【讨论】:

      猜你喜欢
      • 2021-09-22
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 2018-06-22
      • 1970-01-01
      • 2020-08-01
      • 2019-02-14
      相关资源
      最近更新 更多