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

jpa:repositories changes @Repository objects into proxies. Autowiring fails [DATAJPA-112] #538

Closed
spring-projects-issues opened this issue Oct 7, 2011 · 4 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 7, 2011

Adrian opened DATAJPA-112 and commented

When activating jpa:repositories in the context the @Repository annotated objects get somehow proxied and spring is unable to autowire them.
Please have a look at the demo project attached. There you will find a failing test.
If you change the @Repository annotation of the SelectModule class into @Component the testcase is working. It is also working if you remove jpa:repositores from the text-context.xml.


Affects: 1.1 M1

Attachments:

Issue Links:

  • DATAJPA-330 @EnableJpaRepositories activates exception translation for @Repository classes not in basePackages

  • DATACMNS-318 Introduce dedicated annotation to enable exception translation

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 7, 2011

Oliver Drotbohm commented

I inclined to close this one as works as designed for the following reason: the Javadoc of Repository clearly states that by annotating a class with it the class is marked as eligible for DataAccessException translation. The Spring Data reference documentation for the namespace states, that it activates exception translation transparently (not sure this is in the docs for the current release but it will be for the next one). As your class implements an interface Spring choses JDK proxying and only exposes the interface of the class and not the class' type anymore. Thus you cannot refer to the component by its class anymore. We recommend to simply introduce an interface for the component itself which you can refer to then for autowiring or manual access

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2011

Adrian commented

Sorry for answering so late. I didn't get any notification about your comment.

I think my test case does not demonstrate the true problem here. Please add

@Autowired
private SelectModule selectModule;

to the JpaTest class and the test case will not even start due to "Injection of autowired dependencies failed".
Please note, that the SelectModule class does not implement any interfaces.

IMHO adding jpa:repositories to your context should not break the whole DI of your application.

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2011

Oliver Drotbohm commented

We'll that doesn't really add any new aspects to the problem as your still using a class without an interface unless I am not entirely getting you. @Repository specifies the annotated class potentially being proxied. Thus you should refer to those components through an interfaces (which is a good practice anyway)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2011

Adrian commented

I don't want to argue here. I think that the jpa module simply changes the behavior of the DI with @Repository annotated classes and the test case proves that.

I can work around this problem, so you can close it if you want

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

Successfully merging a pull request may close this issue.

None yet
2 participants