You may encounter an error message pointing to the servlet reference bean. Well, there are several steps you can take to fix this problem. We will talk about this in the near future.
Speed up your computer in minutes
This allows you to add EJB annotations to the Inject servlet fields if you are using a Java EE 6 server application such as Glassfish v3. Some people like it:
@InjectPrivate AppManagedBean, managed by the application;@EJBbean private session sessbean;
Remember that these notes are part of CDI context and dependency injection, and you must add the beans.xml deployment descriptor type as well.
But if you can’t even use CDI annotations, find the specific BeanManager interface under java: comp / BeanManager and enable (only) managed coffee beans for it (you can also inject session into managed bean). @ EJB annotations). Also don’t forget to add the beans.xml deployment descriptor.
package mavenproject4;import java.util.Set;import javax.enterprise.context.spi.CreationalContext;import javax.enterprise.inject.spi.Bean;import javax.enterprise.inject.spi.BeanManager;import javax.naming.InitialContext;import javax.naming.NamingException;Public Class Managed Components the beanManager remains closed by the static beanManager; Sounds To attempt InitialContext ic corresponds to the new InitialContext (); beanManager = (BeanManager) ic.lookup ("java: comp / BeanManager"); catch (NameException ex) You are Throw pending IllegalStateException (ex); private beans () public static
T getBean (Class clazz, Stringname) Define > beans = beanManager.getBeans (name); Beans extends Resolve = beanManager.resolve (beans); Creative context createCreationalContext corresponds to beanManager.createCreationalContext (permission); (T) return beanManager.getReference (resolve, clazz, createCreationalContext);
response.setContentType ("text / html; character set = UTF-8");AppManagedBean appmanaged includes ManagedBeans.getBean (AppManagedBean.class, "application");PrintWriter out = response.getWriter ();To attempt out.println (""); out.println ("
"); out.BeanManager "); println (" servlet out.println (" "); out.println (""); out.println ("
" + Appmanaged.getHelloWorld () + ""); out.println (""); out.println ("