In openwebbeans i can inject customer resource using OpenWebBeansPlugin.
eg:
public void startUp()
throws WebBeansConfigurationException
{
try
{
webApplicationContext = createContextLoader(servletContext);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
startupContextLoader(webApplicationContext);
}
catch (Exception e)
{
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, e);
e.printStackTrace();
}
}
public void shutDown()
throws WebBeansConfigurationException
{
if ((webApplicationContext != null) && (webApplicationContext instanceof ConfigurableWebApplicationContext))
((ConfigurableWebApplicationContext)webApplicationContext).close();
}
public Object injectResource(Type type, Annotation[] annotations)
{
if (!(isResource(annotations)))
{
return null;
}
Annotation annot = AnnotationUtil.getAnnotation(annotations, SpringBean.class);
if (annot != null)
{
SpringBean pu = (SpringBean)annot;
String springName = pu.value();
return webApplicationContext.getBean(springName);
}
return null;
}
public boolean isResourceAnnotation(Class<? extends Annotation> clazz)
{
Asserts.assertNotNull(clazz, "clazz parameter can not be null");
XMLAnnotationTypeManager manager = XMLAnnotationTypeManager.getInstance();
if (manager.hasResource(clazz))
{
return true;
}
return (clazz.equals(SpringBean.class));
}
In weld how can i do this?