Injecting a bean from a different Jar in Weld

前端 未结 3 724
轮回少年
轮回少年 2021-01-04 00:43

I have two Jars A and B where A depends on B.

Jar B has a single class:

@ApplicationScoped
public class MyMa         


        
3条回答
  •  無奈伤痛
    2021-01-04 01:19

    One thing, you have to create Qulifier annotation for specify exactly which should be injected.

    @Qualifier
    @Retention(RUNTIME)
    @Target({METHOD, FIELD, PARAMETER, TYPE})
    public @interface UserConfiguration { }
    

    and then..

     @Produces
     @UserConfiguration
     @Named("user")
     public String getUser(){
      return "myUser";
     }
    

    for injection..

    @Inject
    public MyManagedBean(@UserConfiguration String user){
        this.user = user;
    }
    

    see also http://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html_single/#d0e1355

提交回复
热议问题