Java考虑在添加MongoDB支持时在配置异常中定义类型为

sauutmhj  于 2022-10-01  发布在  Java
关注(0)|答案(3)|浏览(207)

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

我读了很多文件,但我不能让它发挥作用。我的提交代码是:

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

如果添加@AutoWire注解,应用程序将不会启动。我认为这应该和官方文件一样。

在src/main/Java/control/UserController.java中

  1. @Autowired
  2. private UserPropsRepository userPropsRepository;

这是我的项目,有人能帮我吗?

https://github.com/GuoJing/spb

我的例外是:

  1. ***************************
  2. APPLICATION FAILED TO START
  3. ***************************
  4. Description:
  5. Field userPropsRepository in controller.UserController required a bean of type 'repository.UserPropsRepository' that could not be found.
  6. Action:
  7. Consider defining a bean of type 'repository.UserPropsRepository' in your configuration.
pcrecxhr

pcrecxhr1#

问题解决了。

1.更改我的项目结构,移动根包、模型和DAO...要来.例如.
1.将Application.java移动到根目录,以便它将自动扫描组件

与此相关的问题和解决方案。

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

bqjvbblv

bqjvbblv2#

  • 我将我的Spring Boot版本更改为2.1.1.RELEASE,问题得到解决。
  • 已清除.mvn文件夹并重建我的项目,问题已解决。
ijxebb2r

ijxebb2r3#

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

  1. @repository("userPropsRepository")
  2. public interface UserPropsRepository extends MongoRepository<UserProps, String> {
  3. UserProps findOne(String id);
  4. UserProps save(UserProps props);
  5. UserProps update(UserProps props);
  6. void delete(UserProps props);
  7. }

相关问题