The @Repository annotation inndicates that an annotated class is a "Repository" (or "DAO").
A class thus annotated is eligible for Spring
DataAccessException
translation. The annotated class is also clarified as to its role in the overall application architecture for the purpose of tools, aspects, etc.
As of Spring 2.5, this annotation also serves as a specialization of
@Component
, allowing for implementation classes to be autodetected through classpath scanning.
I have JpaBlogEntryRepo class in my application. If I forgot to add the @Repository annotation before the class declaration, the following exception will be raised at the time of starting the server (mine is tomcat):
SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogEntryServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private firstapp.core.repositories.BlogEntryRepo firstapp.core.services.impl.BlogEntryServiceImpl.entryRepo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [firstapp.core.repositories.BlogEntryRepo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ... Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private firstapp.core.repositories.BlogEntryRepo firstapp.core.services.impl.BlogEntryServiceImpl.entryRepo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [firstapp.core.repositories.BlogEntryRepo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ... 24 more
No comments:
Post a Comment