-
1. Re: @Alternative that depends of beans inside another jar not being loaded
mkouba May 24, 2013 6:08 AM (in response to alberto_souza)Hi Alberto,
please could you describe your deployment structure more thoroughly (e.g. where is the bean UsuariosController and its dependencies located)?
-
2. Re: @Alternative that depends of beans inside another jar not being loaded
alberto_souza May 24, 2013 7:23 AM (in response to mkouba)Hi Martin,
The UsuariosController is deployed with my webapp. It needs a Request, which is provided for my factory, that is located in other jar, a cdi-plugin for vraptor. The cdi-plugin needs vraptor as dependency and the factory uses a class that is deployed inside vraptor jar. Everything has beans.xml. One detail, i am using weld's scan tag:
[code xml]
<weld:scan>
<weld:exclude name="br.com.caelum.vraptor.**"/>
</weld:scan>
[/code]
And the plugin registers all vraptor's classes manually. It observes the BeforeBeanDiscovery event.
-
3. Re: @Alternative that depends of beans inside another jar not being loaded
mkouba May 24, 2013 7:39 AM (in response to alberto_souza)First I checked the vraptor jar (http://vraptor.caelum.com.br) and it does not contain beans.xml so it's not a bean archive. Could you post the code snippet of the HttpServletRequest factory/producer from a cdi-plugin?
-
4. Re: @Alternative that depends of beans inside another jar not being loaded
alberto_souza May 24, 2013 8:07 AM (in response to mkouba)Hi Martin,
All the code is in my fork. And the scenario described was not pushed yet. If you go to github.com/asouza/vraptor you will see. But this is a functional version, because the plugin is integrated with vraptor core. Now the plugin's code is in other project.
[code java]
@RequestScoped
@Alternative
public class CDIHttpServletRequestFactory{
@Inject
private CDIRequestInfoFactory cdiRequestInfoFactory;
@Produces @RequestScoped
public MutableRequest getInstance(){
return cdiRequestInfoFactory.producesRequestInfo().getRequest();
}
}
@RequestScoped
public class CDIRequestInfoFactory {
private RequestInfo requestInfo;
public void observesRequest(@Observes RequestInfo requestInfo){
this.requestInfo = requestInfo;
}
@Produces @RequestScoped
public RequestInfo producesRequestInfo(){
return requestInfo;
}
}
[/code]
-
5. Re: @Alternative that depends of beans inside another jar not being loaded
mkouba May 24, 2013 8:36 AM (in response to alberto_souza)1 of 1 people found this helpfulI see, is the CDIHttpServletRequestFactory alternative selected for the bean archive which contains UsuariosController? Also you don't need to have @Produces annotation on producesRequestInfo() if you call it directly. To be consistent you should either always call producesRequestInfo() direcly or inject RequestInfo in your producer methods and beans...
-
6. Re: @Alternative that depends of beans inside another jar not being loaded
alberto_souza May 27, 2013 3:17 PM (in response to mkouba)Hi Martin!,
I declared the alternatives in the UsuariosControllers's bean archive and everything worked . Do i really need to declare the alternatives in every bean archive? Is there a workaround?
-
7. Re: @Alternative that depends of beans inside another jar not being loaded
alberto_souza May 27, 2013 9:35 PM (in response to alberto_souza)My problem here is that i want to specialize a vraptor component. But i can't do that because the bean archives only use the alternatives declared within it.
-
8. Re: @Alternative that depends of beans inside another jar not being loaded
mkouba May 28, 2013 1:56 AM (in response to alberto_souza)AFAIK there is no way to achieve this in CDI 1.0 (Weld 1.x/JBoss AS7). However CDI 1.1 (Weld 2.x/WildFly) allows you to declare selected alternatives for an application: http://docs.jboss.org/cdi/spec/1.1/cdi-spec.html#declaring_selected_alternatives
Also note that specialization is not tied to alternatives.
-
9. Re: @Alternative that depends of beans inside another jar not being loaded
alberto_souza May 28, 2013 7:08 AM (in response to mkouba)I see. I did not understand the last comment. I know about alternatives and decorators in order to specialize some implementation. Do you have other idea? I would love to hear .
-
10. Re: @Alternative that depends of beans inside another jar not being loaded
mkouba May 28, 2013 7:20 AM (in response to alberto_souza)You can specialize some bean even if your specializing impl is not an alternative (it doesn't have to be enabled explicitly). E.g. "@Specializes MockService extends Service". If your app contains MockService, Service is completely overriden (see http://docs.jboss.org/cdi/spec/1.1/cdi-spec.html#specialization). However I find specialization a little bit confusing and difficult to use ...
-
11. Re: @Alternative that depends of beans inside another jar not being loaded
alberto_souza May 30, 2013 10:52 AM (in response to mkouba)@Specializes it not working with beans that are registered in my Extension. I don't know why... I am using jboss 7.1.1.final which has the latest version of weld 1. I am a little bit disapointed...