Skip navigation links

Package javax.enterprise.inject

Java Dependency Injection annotations and exceptions.

See: Description

Package javax.enterprise.inject Description

Java Dependency Injection annotations and exceptions. For programmatic access see javax.enterprise.inject.spi.

Example: injecting a servlet using a custom binding type

 package example;

 import example.MyBinding;
 import javax.servlet.*;
 import java.io.*;

 public class MyServlet extends GenericServlet {
    @MyBinding MyBean _bean;

   public void service(ServletRequest req, ServletResponse res)
     throws IOException
   {
     PrintWriter out = res.getWriter();

     out.println("my-bean: " + _bean);
   }
 }
 

Example: creating a custom binding type

 package example;

 import static java.lang.annotation.ElementType.*;
 import static java.lang.annotation.RetentionPolicy.Runtime;
 import java.lang.annotation.*;

 import javax.enterprise.inject.BindingType;

  @BindingType
  @Documented
 Target({TYPE, METHOD, FIELD, PARAMETER})
 Retention(RUNTIME)
 public  @interface MyBinding {
 }
 

Example: configuring using a custom binding type

META-INF/beans.xml
 <Beans xmlns="urn:java:ee" xmlns:example="urn:java:example">

   <example:MyBean>
     <example:MyBinding/>
   </example:MyBean>

 </Beans>
 
Skip navigation links