2

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.
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
GuoJing
  • 13
  • 1
  • 1
  • 11
  • what is the exception are you getting. – Rajith Pemabandu Apr 02 '17 at 04:31
  • @RajithPemabandu *************************** 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. – GuoJing Apr 02 '17 at 04:49
  • have you considered my answer? – Rajith Pemabandu Apr 02 '17 at 05:11

3 Answers3

0

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

Community
  • 1
  • 1
GuoJing
  • 13
  • 1
  • 1
  • 11
0
  • 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.
Gadhia Reema
  • 186
  • 3
  • 17
-1

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);
}
Rajith Pemabandu
  • 616
  • 7
  • 14