當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanManager.createAnnotatedType方法代碼示例

本文整理匯總了Java中javax.enterprise.inject.spi.BeanManager.createAnnotatedType方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanManager.createAnnotatedType方法的具體用法?Java BeanManager.createAnnotatedType怎麽用?Java BeanManager.createAnnotatedType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.enterprise.inject.spi.BeanManager的用法示例。


在下文中一共展示了BeanManager.createAnnotatedType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testInjectionTarget

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@Test
public void testInjectionTarget() {
	BeanManager beanManager = current().getBeanManager();
	// CDI uses an AnnotatedType object to read the annotations of a class
	AnnotatedType<String> type = beanManager.createAnnotatedType(String.class);
	// The extension uses an InjectionTarget to delegate instantiation,
	// dependency injection
	// and lifecycle callbacks to the CDI container
	InjectionTarget<String> it = beanManager.createInjectionTarget(type);
	// each instance needs its own CDI CreationalContext
	CreationalContext<String> ctx = beanManager.createCreationalContext(null);
	// instantiate the framework component and inject its dependencies
	String instance = it.produce(ctx); // call the constructor
	it.inject(instance, ctx); // call initializer methods and perform field
								// injection
	it.postConstruct(instance); // call the @PostConstruct method
	// destroy the framework component instance and clean up dependent
	// objects
	assertNotNull("the String instance is injected now", instance);
	assertTrue("the String instance is injected now but it's empty", instance.isEmpty());
	it.preDestroy(instance); // call the @PreDestroy method
	it.dispose(instance); // it is now safe to discard the instance
	ctx.release(); // clean up dependent objects
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:25,代碼來源:InjectSPITestCase.java

示例2: getAnnotatedMember

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private <X, A extends AnnotatedMember<? super X>> A getAnnotatedMember(Class<X> javaClass, String memberName,
		BeanManager beanManager) {
	AnnotatedType<X> type = beanManager.createAnnotatedType(javaClass);
	for (AnnotatedField<? super X> field : type.getFields()) {
		if (field.getJavaMember().getName().equals(memberName)) {
			return (A) field;
		}
	}
	for (AnnotatedMethod<? super X> method : type.getMethods()) {
		if (method.getJavaMember().getName().equals(memberName)) {
			return (A) method;
		}
	}
	throw new IllegalArgumentException("Member " + memberName + " not found on " + javaClass);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:17,代碼來源:InjectSPITestCase.java

示例3: inject

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
/**
 * Perform injection into a non-CDI managed bean.
 * <p>
 * An example of this is a JSP Tag
 * <p>
 * @param <T>
 * @param bean
 */
public static <T> T inject( T bean )
{
    BeanManager beanManager = getBeanManager();
    AnnotatedType<T> annotatedType = beanManager.<T>createAnnotatedType( (Class<T>) bean.getClass() );
    InjectionTarget<T> injectionTarget = beanManager.createInjectionTarget( annotatedType );
    CreationalContext ctx = beanManager.createCreationalContext( null );
    injectionTarget.inject( bean, ctx );
    return bean;
}
 
開發者ID:peter-mount,項目名稱:opendata-common,代碼行數:18,代碼來源:CDIUtils.java

示例4: declareAsInterceptorBinding

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
private static <T extends Annotation> void declareAsInterceptorBinding(Class<T> annotation, BeanManager manager, BeforeBeanDiscovery bbd) {
    AnnotatedType<T> annotated = manager.createAnnotatedType(annotation);
    Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
    for (AnnotatedMethod<? super T> method : annotated.getMethods()) {
        methods.add(new AnnotatedMethodDecorator<>(method, NON_BINDING));
    }
    bbd.addInterceptorBinding(new AnnotatedTypeDecorator<>(annotated, INTERCEPTOR_BINDING, methods));
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:9,代碼來源:MetricCdiInjectionExtension.java

示例5: beforeBeanDiscovery

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
    AnnotatedType<ConfigProducer> configBean = bm.createAnnotatedType(ConfigProducer.class);
    bbd.addAnnotatedType(configBean);
}
 
開發者ID:wildfly-extras,項目名稱:wildfly-microprofile-config,代碼行數:5,代碼來源:ConfigExtension.java


注:本文中的javax.enterprise.inject.spi.BeanManager.createAnnotatedType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。