本文整理汇总了Java中javax.enterprise.inject.spi.Bean.getScope方法的典型用法代码示例。如果您正苦于以下问题:Java Bean.getScope方法的具体用法?Java Bean.getScope怎么用?Java Bean.getScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.enterprise.inject.spi.Bean
的用法示例。
在下文中一共展示了Bean.getScope方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processBean
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
/**
* Process a bean. Checks the bean for @Service annotation and if it is found, verifies
* the bean scope and marks it for export as service at a later stage.
*
* @param event The process bean event. See CDI specification
* @param <T> The type of the bean
*/
public <T> void processBean(@Observes ProcessBean<T> event) {
Bean<T> bean = event.getBean();
Service service = BeanExporter.getServiceDefinition(bean);
if (service == null) {
return;
}
// Check the scope. Must be global.
Class<? extends Annotation> scope = bean.getScope();
if (!scope.equals(ComponentScoped.class) && !scope.equals(ApplicationScoped.class)) {
// Set an error.
event.addDefinitionError(new Exception("beans annotated with @Service must have a global scope"));
return;
}
// Mark the bean as exportable.
exportedBeans.put(bean, null);
}
示例2: lookup
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
public Object lookup(String beanName, String sessionID) {
NGSessionScopeContext.setCurrentContext(sessionID);
Set<Bean<?>> beans = beanManager.getBeans(beanName);
Class beanClass = CommonUtils.beanNamesHolder.get(beanName);
if (beans.isEmpty()) {
beans = beanManager.getBeans(beanClass, new AnnotationLiteral<Any>() { //
});
}
Bean bean = beanManager.resolve(beans);
Class scopeAnnotationClass = bean.getScope();
Context context;
if (scopeAnnotationClass.equals(RequestScoped.class)) {
context = beanManager.getContext(scopeAnnotationClass);
if (context == null)
return bean.create(beanManager.createCreationalContext(bean));
} else {
if (scopeAnnotationClass.equals(NGSessionScopeContext.class)) {
context = NGSessionScopeContext.getINSTANCE();
} else {
context = beanManager.getContext(scopeAnnotationClass);
}
}
CreationalContext creationalContext = beanManager.createCreationalContext(bean);
Object reference = context.get(bean, creationalContext);
// if(reference==null && scopeAnnotationClass.equals(RequestScoped.class)){
// reference= bean.create(beanManager.createCreationalContext(bean));
// }
return reference;
}