스프링 데이터 MongodB 1.4.2.Release 버전을 사용 중입니다. Spring Data MongoDB의 경우 사용자 정의 저장소 인터페이스와 구현을 한 위치에 만들고 사용자 정의 쿼리 함수 getUsersName(Users users)
을 작성했습니다.스프링 데이터 MongoDB org.springframework.data.mapping.PropertyPath에서 유형에 대한 속성을 찾을 수 없습니다.
그러나 나는 아직도 예외 아래에 무엇입니까 :
Caused by: org.springframework.data.mapping.PropertyReferenceException:
No property get found for type Users! at org.springframework.data.mapping.PropertyPath. (PropertyPath.java:75) at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) at
org.springframework.data.repository.query.parser.Part.(Part.java:76) at
org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:201) at
org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:291) at
org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:271) at
org.springframework.data.repository.query.parser.PartTree.(PartTree.java:80) at
org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.(PartTreeMongoQuery.java:47)
아래는 내 봄 데이터 MongoDB의 구조입니다 :
/* Users Domain Object */
@Document(collection = "users")
public class Users {
@Id
private ObjectId id;
@Field ("last_name")
private String last_name;
@Field ("first_name")
private String first_name;
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
}
/* UsersRepository.java main interface */
@Repository
public interface UsersRepository extends MongoRepository<Users,String>, UsersRepositoryCustom {
List findUsersById(String id);
}
/* UsersRepositoryCustom.java custom interface */
@Repository
public interface UsersRepositoryCustom {
List<Users> getUsersName(Users users);
}
/* UsersRepositoryImpl.java custom interface implementation */
@Component
public class UsersRepositoryImpl implements UsersRepositoryCustom {
@Autowired
MongoOperations mongoOperations;
@Override
public List<Users> getUsersName(Users users) {
return mongoOperations.find(
Query.query(Criteria.where("first_name").is(users.getFirst_name()).and("last_name").is(users.getLast_name())), Users.class);
}
/* Mongo Test function inside Spring JUnit Test class calling custom function with main UsersRepository interface */
@Autowired
private UsersRepository usersRepository;
@Test
public void getUsersName() {
Users users = new Users();
users.setFirst_name("James");`enter code here`
users.setLast_name("Oliver");
List<Users> usersDetails = usersRepository.getUsersName(users);
System.out.println("users List" + usersDetails.size());
Assert.assertTrue(usersDetails.size() > 0);
}
는 사용자 정의 저장소이 문서에 언급 된대로 작동하지 않습니다 - HTTP ://docs.spring.io/spring-data/data-mongo/docs/1.4.2.RELEASE/reference/html/repositories.html#repositories.custom-implementations – Navi
작동합니다. 구현 클래스 이름이 올바르지 않은 것 같습니다. – Navi