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

Support for injection via @Resource annotation #45

Closed
alexey-krylov opened this issue Feb 19, 2013 · 4 comments
Closed

Support for injection via @Resource annotation #45

alexey-krylov opened this issue Feb 19, 2013 · 4 comments

Comments

@alexey-krylov
Copy link

Please add support for injection via @resource annotation:
@resource
public void setResource(Jsr250Resource resource) {
this.resource = resource;
}

With this feature Governator will be fully JSR-250 compliant and can fully replace old Mycila-Guice project.

You can see implementation example in Mycila-Guice project:
com.mycila.inject.jsr250.Jsr250KeyProvider

I've tried to combine Mycila-Guice and Governator with:

injector = LifecycleInjector.builder().withBootstrapModule(new BootstrapModule() {
@OverRide
public void configure(BootstrapBinder binder) {
binder.install(Jsr250.newJsr250Module());
}
}).withModules(allModules).inStage(Stage.PRODUCTION).createInjector();

But in this case @PostConstruct methods called twice :(

@Randgalt
Copy link
Contributor

This is a good idea. I'll look into this and add it if I can.

@Randgalt
Copy link
Contributor

Have a look at Randgalt@ee385df and see if it will meet your needs.

@alexey-krylov
Copy link
Author

Jordan, unfortunately this commit doesn't help to my situation. I have this exception:

Caused by: javax.naming.NameNotFoundException: No resource found that matches: com.netflix.governator.lifecycle.LifecycleManager$1@13e573
at com.netflix.governator.lifecycle.LifecycleManager.findResource(LifecycleManager.java:556)
at com.netflix.governator.lifecycle.LifecycleManager.setMethodResource(LifecycleManager.java:469)

For my understanding of JSR-250 - that @resource annotation allows you to inject anything like with regular @Inject annotation and there is no mandatory need to explicitly bind this injected resources.

Many 3rd party frameworks assumes that with @resource they will get dependencies - for example take a look at:
https://github.com/AxonFramework/AxonFramework/blob/master/core/src/main/java/org/axonframework/eventhandling/scheduling/quartz/QuartzEventScheduler.java line 167

Also i have attached my junit test for this situation:
http://www.filedropper.com/resource-test

@Randgalt
Copy link
Contributor

OK - I added a default ResourceLocator that looks-up via the Guice Injector. Your test now pass and have been included in the Governator code. This change will be released soon.

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

2 participants