简体   繁体   中英

Java Consider defining a bean of type in your configuration exception when add mongoDB support

I have a very simple Java Springboot project connect to the database. Still, I want a mongoDB connection and I could use mongoDB as well.

I read lots of document and I can't make it work. And my commits code is:

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

If adding @AutoWired annotation, application will not start. I think this should be same as official document.

in src/main/java/controller/UserController.java

@Autowired
private UserPropsRepository userPropsRepository;

Here is my project, could anybody help me?

https://github.com/GuoJing/spb

My Exception is:

***************************
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.

Problem solved.

  1. Change my project structure, move root Package and Model and Dao ... to com.example.model ...
  2. Move Application.java to root so it will scan components automatically

Related to this same problem and solution.

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

  • I changed my Spring Boot version to 2.1.1.RELEASE and the issue was solved.
  • Cleared the .mvn folder and rebuild my project and the issue was resolved.

suppose you are missing @Repository annotation in the UserPropsRepository interface.

   @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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM