Question: Use Weld-Unit with spring data JPA
d3rdud3 opened this issue · 4 comments
Hi everybody,
I am currently facing the issue to use Weld-JUnit5 in a project in combination with JPA repositories which are getting injected by spring data JPA as a replacement of using the arquillian framework. The repositories are only interfaces and the implementations are getting created at runtime. By using @EnableAutoWeld. The implementations cannot be found at the time the test is starting. Does anyone have experience in using Spring Data JPA in combination with WeldJunit and does know what to do here ? Would be great. Thanks a lot !
Hello,
I am not sure I understand the question so what is below is just a guesswork - take it with a pinch of salt.
Weld-junit is basically just an extension starting Weld SE for you in your test environment. It doesn't know anything about JPA and/or Spring. From what you describe, I suspect there is some library that generates implementations (== CDI beans?) from those interfaces. So what you might need to do is to make sure that library will be picked up and processed.
By default weld-junit (or rather @EnableAutoWeld
) only looks at the test class and tries to "divine" what classes are needed as beans to keep the deployment minimal; as unit tests should be. Discovery is by default off but you can provide custom Weld
object that will either add necessary classes/extension/etc or will enable discovery. Take a look at WeldInitiator
and some tests using it to see what you can achieve with it.
Hi everybody,
I am currently facing the issue to use Weld-JUnit5 in a project in combination with JPA repositories which are getting injected by spring data JPA as a replacement of using the arquillian framework. The repositories are only interfaces and the implementations are getting created at runtime. By using @EnableAutoWeld. The implementations cannot be found at the time the test is starting. Does anyone have experience in using Spring Data JPA in combination with WeldJunit and does know what to do here ? Would be great. Thanks a lot !
Yes, trying to do the same thing. Looks like spring data JPA repository beans are not supported(?), because WELD is complaining about org.jboss.weld.exceptions.DeploymentException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
when using autodiscovery.
[EDIT] Ok, @Eager
annotation on spring data repo interface was causing premature loading of the repository. It works when using lazy mode [/EDIT]
Spring Data Commons Repository
has built-in CDI support.
If set discovery-mode to all, Spring Data Repository
can be scanned by a CDI container and treated as CDI beans automaticially.
Since there was no follow up from the author of this question and the subsequent answers suggest this is solveable with discovery enabled, I'll close this issue.