Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods! #348

Open
dulshand opened this issue Jul 11, 2021 · 0 comments

Comments

@dulshand
Copy link

Expected Behavior

Repository method should return records as per filter criteria stated in @query

Actual Behavior

During the springboot application start up it fails with below error
Getting error You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
Complete error:
2021-07-11 15:45:34.632 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Spring Data DynamoDB Version: 5.2.5 (2.2)
2021-07-11 15:45:34.634 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Spring Data Version: 2.0.9.RELEASE
2021-07-11 15:45:34.635 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : AWS SDK Version: 1.11.771
2021-07-11 15:45:34.635 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Java Version: 11.0.4 - OpenJDK 64-Bit Server VM 11.0.4+10-b304.77
2021-07-11 15:45:34.635 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Platform Details: Windows 10 10.0
2021-07-11 15:45:34.635 WARN 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : This Spring Data DynamoDB implementation might not be compatible with the available Spring Data classes on the classpath!
NoDefClassFoundExceptions or similar might occur!
2021-07-11 15:45:34.823 WARN 30940 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dynamoDbController': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dynamoDbRepository': Unsatisfied dependency expressed through field 'myCRUDRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myCRUDRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
2021-07-11 15:45:34.828 INFO 30940 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]

Steps to Reproduce the Problem

  1. Create springboot app with
org.springframework.boot spring-boot-starter-parent 2.0.4.RELEASE org.springframework.boot spring-boot-starter-web com.amazonaws aws-java-sdk-dynamodb 1.11.771 io.github.boostchicken spring-data-dynamodb 5.2.5 org.springframework.boot spring-boot-starter-test test 1. Then create a custom crud Repository

package com.springboot.repository;

import com.springboot.model.Student;
import com.springboot.model.StudentKey;
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
import org.socialsignin.spring.data.dynamodb.repository.ExpressionAttribute;
import org.socialsignin.spring.data.dynamodb.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;
@EnableScan
public interface MyCRUDRepository extends CrudRepository<Student, StudentKey> {
@query(filterExpression = "contains(#field, :value)",
expressionMappingNames = {@ExpressionAttribute(key = "#field", value = "firstName")},
expressionMappingValues = {@ExpressionAttribute(key=":value", parameterName = "firstName")})
List findList(@param("firstName") String firstName);
}

Model Classes:

package com.springboot.model;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;

import java.io.Serializable;

public class StudentKey implements Serializable {
private static final long serialVersionUID = 2310511711421469613L;

public StudentKey() {
}

public StudentKey(String studentId) {
    this.studentId = studentId;
}

private String studentId;


public StudentKey(String studentId, String lastName) {
    this.studentId = studentId;
    this.lastName = lastName;
}

@DynamoDBHashKey(attributeName = "studentId")
@DynamoDBAutoGeneratedKey
public String getStudentId() {
    return studentId;
}

public void setStudentId(String studentId) {
    this.studentId = studentId;
}
@DynamoDBRangeKey
public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

private String lastName;

}
package com.springboot.model;

import java.io.Serializable;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDocument;

@DynamoDBDocument
public class Address implements Serializable {

private static final long serialVersionUID = 1L;

private String addressLine1;
private String addressLine2;
private String state;
private String city;
private String zipCode;

@DynamoDBAttribute
public String getAddressLine1() {
	return addressLine1;
}

public void setAddressLine1(String addressLine1) {
	this.addressLine1 = addressLine1;
}

@DynamoDBAttribute
public String getAddressLine2() {
	return addressLine2;
}

public void setAddressLine2(String addressLine2) {
	this.addressLine2 = addressLine2;
}

@DynamoDBAttribute
public String getState() {
	return state;
}

public void setState(String state) {
	this.state = state;
}

@DynamoDBAttribute
public String getCity() {
	return city;
}

public void setCity(String city) {
	this.city = city;
}

@DynamoDBAttribute
public String getZipCode() {
	return zipCode;
}

public void setZipCode(String zipCode) {
	this.zipCode = zipCode;
}

}

package com.springboot.model;

import java.io.Serializable;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
import org.springframework.data.annotation.Id;

@DynamoDBTable(tableName = "student")
public class Student implements Serializable {

private static final long serialVersionUID = 1L;
@DynamoDBHashKey(attributeName = "studentId")
public String getId() {
	return (id != null)?id.getStudentId():null;
}

public void setId(String studentId) {
	if (this.id == null) {
		this.id = new StudentKey(studentId);
	} else {
		this.id.setStudentId(studentId);
	}
}
@Id
StudentKey id;


@DynamoDBRangeKey(attributeName = "lastName")
public String getLastName() {
	return id != null ? id.getLastName() : null;
}

public void setLastName(String lastName) {
	if (this.id == null) {
		this.id = new StudentKey();
	}
	this.id.setLastName(lastName);
}

private String firstName;
private String age;
private Address address;



@DynamoDBAttribute
public String getFirstName() {
	return firstName;
}

public void setFirstName(String firstName) {
	this.firstName = firstName;
}



@DynamoDBAttribute
public String getAge() {
	return age;
}

public void setAge(String age) {
	this.age = age;
}

@DynamoDBAttribute
public Address getAddress() {
	return address;
}

public void setAddress(Address address) {
	this.address = address;
}

}

main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : This Spring Data DynamoDB implementation might not be compatible with the available Spring Data classes on the classpath!

Specifications

  • Spring Data DynamoDB Version: 5.2.5 (2.2)
  • Spring Data Version: 2.0.9.RELEASE
  • AWS SDK Version: 1.11.771
  • Java Version: 11.0.4 - OpenJDK 64-Bit Server VM 11.0.4+10-b304.77
  • Platform Details: Windows 10 10.0

All those information are logged by org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory on INFO level on startup.
Or use java -version and mvn dependency:tree | grep -E 'spring|aws' to provide those version numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant