1
votes

I have the following mongo configuration:

<context:component-scan base-package="com.example" />
<mongo:repositories base-package="com.example.repositories.mongodb" />

I have the repository as follows:

package com.example.repositories.mongodb;
public interface ReviewRepository extends CrudRepository<Review, String> {...}

and the bean:

package com.example.domain;
@Document(collection="Review")
public class Review implements Serializable { ... }

Unfortunately, when I start the app, I get the following exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.example.repositories.mongodb.ReviewRepository com.example.Controller.reviewRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reviewRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Not an managed type: class com.example.domain.Review

....

Caused by: java.lang.IllegalArgumentException: Not an managed type: class com.example.domain.Review

I think that this might be caused by the repository and the bean it manages not being in the same package. But I get the same issue also when I do place them in the same package. Any ideas?

1
it usually means that the persistence layer isn't aware of some class (in this case - Review). do you have both mongo:repositories and context:component-scan set in the same context? - pl47ypus
yes. i have the component scan in the same context. any other ideas? thanks. - checklist
unfortunately, no... aside for not being in the same context, the only other thing that comes to mind (although not likely to happen) is that the @Document annotation isn't the right one. i need to see more code - pl47ypus

1 Answers

0
votes

In the same project we were also using mysql and it was scanning the package: com.example.repositories. This caused the issue and once we changed it to com.example.repositories.mysql it was solved.