CDI Replacement for @ManagedProperty

☆樱花仙子☆ 提交于 2019-12-04 06:35:45

Since your cdsList is no bean class you need a producer field or a producer method to make it injectable.

Example for producer field:

import javax.enterprise.inject.Produces;
...
@Named 
@Produces 
private List<CDXmlDescriptor> cdsList;

Example for producer method:

import javax.enterprise.inject.Produces;

private List <CDXmlDescriptor> cdsList;
...
@Named("cdsList") 
@Produces 
public List<CDXmlDescriptor> getCdsList {
  return cdsList;
};

This works if there is no other producer field or producer method that returns the same bean type. Otherwise you need to introduce a special qualifier for your producer field to resolve ambiguity:

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.inject.Qualifier;


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

with

@Named @Produces @CdsList
private List<CDXmlDescriptor> cdsList;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!