Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rabbitMqController': Unsatisfied dependency expressed through field 'recordsReprositry'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.rabbitmq.config.RecordsReprositry' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
1
votes
please, show the way you defined the repository. the stacktrace is not enough to help you out
– Andrew Tobilko
package com.rabbitmq.config; import java.util.UUID; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository public interface RecordsReprositry extends CrudRepository<Records, Long>{ public Records findById(UUID id); }
– Usman Yaqoob
you can edit your question to provide additional info. Paste the controller and the repository code there
– Andrew Tobilko
these are annotations with autowired and requestmapping @RestController public class RabbitMqController { Autowired private RecordsReprositry recordsReprositry; RequestMapping(name="/btsocr", method=RequestMethod.GET) public String btsOCR() throws Exception { return "Working"; } }
– Usman Yaqoob
Why are you defining beans within someone else's package namespace?
– chrylis -cautiouslyoptimistic-
2 Answers
0
votes
Try JPA from spring... (DOC : http://docs.spring.io/spring-data/jpa/docs/current/reference/html/)
Example:
@Repository
public interface MyRepository extends JpaRepository<EntityName,Long> {
// here you can write your query; example:
EntityName findByAttribute(Type value);
// or
@Query("SELECT * FROM EntityName t WHERE t.ID=?1")
EntityName findByID(Long id);
}
Then you can use this repository in service (you must use autowired)
Example:
@Service
public class MyService{
@Autowired
private MyRepository repo;
// here you can call in a method your query
public EntityName example() {
EntityName e = repo.findByID((long)1);
return e;
}
}
Important: the repository your must use it only in service and the service you must use it in controller
0
votes
It looks like you are annotated interface..while you should put @repository to its implementation class.
package com.rabbitmq.config;
import java.util.UUID;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public **interface** RecordsReprositry extends CrudRepository<Records, Long>{
public Records findById(UUID id);
}