Resource Injection Annotation

Hey All,
I am experiencing an issue with the @Resource Injection annotation.
Following is attached my code from my class. QueueConnectionFactory is null.
Wierdly enough when I copy over this code and @Resource Injection in an MDB it works fine!
Any ideas of why this might be.
I am using WLS 10.3.5
@Stateless
public class dummysFriend implements dummysFriendRemote, dummysFriendLocal{
     @Resource(name = "ConnectionFactory-0",
     mappedName = "jms/connectionFactory",
     description = "Connection Factory for WLS")
     private QueueConnectionFactory connectionFactory;
     @Resource(name = "DistributedQueue-3",
     mappedName = "jms/provisionASDLQueue",
     description = "Queue which holds tokenized ASDL(s) for provision")
private Queue provisionASDLQueue;
private QueueConnection queueConnection = null;
private QueueSession queueSession = null;
private QueueSender queueSender = null;
public dummysFriend() {
// TODO Auto-generated constructor stub
@PostConstruct
public void initialize(){
try {
          queueConnection = connectionFactory.createQueueConnection();
          queueSession = queueConnection.createQueueSession(true,
                         Session.AUTO_ACKNOWLEDGE);
          queueSender = queueSession.createSender(provisionASDLQueue);
          MapMessage message = queueSession.createMapMessage();
     message.setString("ASDL", "123");
     message.setString("Token", "456");
     // Sending message to queue
     System.out.println("Sending Message");
     queueSender.send(message);
     // Closing connections
     queueSender.close();
     queueSession.close();
     queueConnection.close();
} catch (JMSException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
}

I am experiencing an issue with the @Resource Injection annotation. Can you post what the issue is that you are seeing?
-steve-

Similar Messages

  • Resource injection in DAO?

    I use a Data Acces Object pattern in a Java EE 5 Web-Tier Application.
    The servlets (and JSP) in the front-end call a separate object that that hides the implementation of accessing data in the databases and maintains the connection to databases.
    Can I use the new Resource Injection annotations to simplify the JNDI and DataSoucce code in my DAO class?
    I have read that Resource Injection only works in Container managed objects like Servlets (but not in JSP which can be complied after deployment).
    Can you point me to a runnable sample application that uses Resource Injection to simplify the JNDI and DataSoucre code?

    Sample Application Listener
    package com.eshop.web;
    import com.eshop.biz.DBAccessor;
    import com.eshop.biz.ShoppingCart;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.PersistenceUnit;
    import javax.servlet.ServletContextListener;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.http.HttpSessionListener;
    import javax.servlet.http.HttpSessionEvent;
    * @author Aliyu Musa
    * @version
    * Web application lifecycle listener.
    public class ShopListener implements ServletContextListener, HttpSessionListener {
    @PersistenceUnit(name="e-unit")
    private EntityManagerFactory emf;
    * ### Method from ServletContextListener ###
    * Called when a Web application is first ready to process requests
    * (i.e. on Web server startup and when a context is added or reloaded).
    * For example, here might be database connections established
    * and added to the servlet context attributes.
    public void contextInitialized(ServletContextEvent evt) {   
    DBAccessor db=new DBAccessor(emf);
    evt.getServletContext().setAttribute("db",db);
    * ### Method from ServletContextListener ###
    * Called when a Web application is about to be shut down
    * (i.e. on Web server shutdown or when a context is removed or reloaded).
    * Request handling will be stopped before this method is called.
    * For example, the database connections can be closed here.
    public void contextDestroyed(ServletContextEvent evt) {
    // TODO add your code here e.g.:
    Connection con = (Connection) e.getServletContext().getAttribute("con");
    try { con.close(); } catch (SQLException ignored) { } // close connection
    * ### Method from HttpSessionListener ###
    * Called when a session is created.
    public void sessionCreated(HttpSessionEvent evt) {
    ShoppingCart cart=new ShoppingCart();
    evt.getSession().setAttribute("cart",cart);
    evt.getSession().setMaxInactiveInterval(10*60*60);
    * ### Method from HttpSessionListener ###
    * Called when a session is destroyed(invalidated).
    public void sessionDestroyed(HttpSessionEvent evt) {
    evt.getSession().invalidate();
    }

  • Resource Injection in Web Tier (JSP and Servlets)

    Hi All
    I was wondering whether someone will be kind enough enough to clear this up for me as it causing me some confusion. I am using OC4J 10.1.3.4 and Java 5. I have been reading the documentation on OC4J and at one point it says that OC4J does not support resource injection(i.e. annotations) in the web tier and you'll have to use JNDI to access resources such as EJBs from the Web tier(see Sub heading Servlet or JSP Client on http://download.oracle.com/docs/cd/B25221_04/web.1013/b14428/usclient.htm) but at other points in the documentation, it seems to suggest that that resource injection is supported see(http://database.in2p3.fr/doc/oracle/Oracle_Application_Server_10_Release_3/web.1013/b28221/undejbs001.htm#CIHFEJAC).
    I am just wondering what the definitive answer is. Does OC4J support resource injection in the web client(in particular, JSP) or not. BTW I am trying to inject an EJB into a JSP client. It doesn't seem to work with resource injection but works OK with JNDI.
    Thanks

    Does any one have any sort of explanation on this?

  • JSFWARNING: JSF1033: Resource injection is DISABLED.

    Anyone else have this problem using the JSF 1.2 implementation bundled with Weblogic 10?
    JSFWARNING: JSF1033: Resource injection is DISABLED.
    At start-up I get the warning and dependency injection doesn't work in backing-beans, etc.
    I've checked the various config files for compliance and everything seems to look good.
    Thanks.

    Well according to:
    http://e-docs.bea.com/wls/docs100/webapp/annotateservlet.html
    JSF backing-beans aren't one of the supported types.
    However according to the JEE5 spec they are.
    I guess Weblogic 10 isn't fully JEE5 compliant, even though it's passed certification. :_|

  • Resource Injection Question -to do with where main is...

    Hi, I've just been doing some jms stuff, and I've found that if I have a class which is just for main, and I send messages in a different class called from main, my resource injection doesn't occur.
    However if the main method is in the class which I send the messages from, resource injection does occur.
    Why is this?? is it something to do with the type of class or something???

    I read that thread and in the SAP library which is quoted, it says, "you can split up the whole dataset for an InfoCube into several, smaller, physically independent and redundancy-free units."
    So what is meant by physically independent in this definition? The way I've described it seems compatible, since data of similar partitions are physically seperate on the disk, though again I'm not sure if its true.
    More inputs would be appreciated... points have and will continue to be awarded.
    Edited by: Benson Wong on Mar 4, 2010 10:38 PM

  • Resource injection in tag handler

    I can't seem to find a straight answer for this anywhere. Using release 9.1 of the Sun Application Server, should resource injection in a tag handler be working? Tak something really simple like this:
    public class TestHandler extends SimpleTagSupport {
        @EJB SomeEJBLocal beanInstance;
        public void doTag() throws JspException {
    } When I try this, beanInstance is null. Is this a configuration issue or does this just not work yet?

    Found the answer myself. When the web module was being ported over, the web.xml was copied as-is. It still had version 2.4 as an attribute to the web-app element. Changing the attributes to match a newly created 2.5 version fixed the problem.

  • EJB Client/Resource Injection

    Hi,
    could anyone explain to me why the field into which an EJB reference in an EJB client can be injected has to be static? I've read the following in the EJB3.0 tutorial (see below), but I don't know what "static context" means exactly. Care to explain, anyone?
    Thanks, Michael
    Creating a Reference to an Enterprise Bean Instance
    "Java EE application clients refer to enterprise bean instances by annotating static fields with the @EJB annotation. The annotated static field represents the enterprise bean's business interface, which will resolve to the session bean instance when the application client container injects the resource references at runtime.
    @EJB
    private static Converter converter;
    The field is static because the client class runs in a static context."

    The question was about why the field needs to be marked static. mappedName is a separate issue. The reason injected fields/methods in Application Clients need to be marked static is because of the Application Client programming model. It has always been the case that for an Application Client component the developer writes a static void main() method as the entry point, much like a regular Java Client. This means that the Application Client container invokes the application code with a static invocation, i.e. there is no instance of the main class. Injection is only useful if it takes place before the application code runs, so to accomplish that without changing the Application Client programming model, the Java EE platform spec requires that injected fields/methods be marked static.
    As for mappedName, it deals with how to map the ejb dependency to the target bean. By default in SUN's implementation, the remote @EJB dependency will map to the global JNDI name formed by taking the fully qualified type of the remote business interface, in this case <packagename>.Converter. That will work as long as the target Remote EJB has that global JNDI name. If the target Remote EJB's global JNDI name were "GlobalJNDIName", then you would need to explicitly assign that to the client's ejb dependency, as this example shows. That can be done either by using the mappedName() attribute or sun-application-client.xml.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Dependency injection/annotation Error

    Greetings,
    Hello everybody !
    This topic's about a problem I'm currently experiencing while trying to deploy a Web Application that makes a call to an EJB using Dependency injection from a Servlet. This is the Stack trace generated when I attempt to deploy my web app:
    DeployerRunnable.run Error parsing annotation for class org.servlet.TestServletoracle.oc4j.admin.internal.DeployerException: Error parsing annotation for class org.servlet.TestServlet
    at oracle.oc4j.admin.internal.DeployerBase.execute(DeployerBase.java:126)
    at oracle.oc4j.admin.jmx.server.mbeans.deploy.OC4JDeployerRunnable.doRun(OC4JDeployerRunnable.java:52)
    at oracle.oc4j.admin.jmx.server.mbeans.deploy.DeployerRunnable.run(DeployerRunnable.java:81)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:619)
    Here's a Snippet from the Servlet that's making the call:
    *public class TestServlet extends HttpServlet {*
         *@EJB(beanName="MathEjbBean")*
         private org.logic.MathEjbBeanRemote ejb;
         protected void doGet(HttpServletRequest request,
                   *HttpServletResponse response) throws ServletException, IOException {*
              ejb.sum(1, 2);
    Here's the EJB implementation:
    *@Stateless*
    *@StatelessDeployment*
    *public class MathEjbBean implements MathEjbBeanRemote, MathEjbBeanLocal {*
         *@Override*
         *public int sum(int a, int b) {*
              *// TODO Auto-generated method stub*
              return a + b;
    Finally, I will post the Container-specific Deployment descriptor:
    <?xml version="1.0" encoding="utf-8"?>
    <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" deployment-version="" deployment-time="128f9bdc917" schema-major-version="10" schema-minor-version="0" >
    <enterprise-beans>
    <session-deployment name="MathEjbBean" tx-retry-wait="60" location="MathEjbBean" local-location="MathEJB_MathEjbBeanLocal" persistence-filename="MathEjbBean">
    </session-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping name="<default-ejb-caller-role>" impliesAll="true" />
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>
    Up until this moment, I still have no clue, about the reason why I can't inject my EJB in the Web-app's Servlet.
    Please Help Me
    It's so hard to find information about this problem on the internet.
    Best Regards,
    Jose.

    Hello there !
    I've corrected this problem by using the same name for the @Stateless annotation and the display-name tag in the ejb-jar file, for @EJB this name should match also.
    Good Luck, hope this is helpful in the future.

  • SessionBean Resource Injection

    hi,
    there ist a possibility at EJB 2.1 to get Data from ejb-jar.xml over <env-enty> ...
    ist there any possibility or alternative at EJB 3.0 to get Data from descriptors? EJB 3.0 dosn't provide <env-entry> in ejb-jar.xml.
    thanks
    Hasan

    Hi Hasan,
    I'm not sure I understand your question. EJB 3.0 does allow you to define env-entry.
    You also have the option of injecting the value instead of doing a lookup.
    E.g., you would put the following in your ejb-jar.xml within a particular <session>
    or <message-driven> entry.
    <env-entry>
    <env-entry-name>value1</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>Foo</env-entry-value>
    </env-entry>
    Then, in the bean class, you put the following :
    @Resource(name="value1") String value;
    Notice how the name attribute of @Resource matches the env-entry-name
    in the ejb-jar.xml. That means you could also lookup the value in the
    bean's component environment :
    String value = (String) new InitialContext().lookup("java:comp/env/value1");
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • JSF 2.0 Resource injection for @ApplicationScoped ManagedBean. Problem.

    Hi, guys. I've got two ManagedBeans with @ApplicationScoped
    @ManagedBean(name = "config", eager=true)
    @ApplicationScoped
    public class Config {
    and
    @ManagedBean(name = "server")
    @ApplicationScoped
    public class Server {
    @ManagedProperty(value = "#{config}")
    private Config config;
    public Config getConfig() {
    return config;
    public void setConfig(Config config) {
    this.config = config;
    public ServerNavCntrl() {
    log.info("Initiated success. Config instance is " + config);
    The problem is that Server initiated with NULL config value. Why is that? Is that a bug?
    Using jsf 2.0.2 and glassfish 3

    Mmmmm ... try it:
    FacesContext fc = FacesContext.getCurrentInstance();
    MyManagedBean mb = (MyManagedBean) fc.getApplication().getELResolver().getValue(fc.getELContext(), null, "mymanagedbean");
    MyEJBRemote ejb = mb.getMyEJB();MyManagedBean have the EJB inyected, getMyEJB just return the instance.
    Maybe work, however i'm not sure.

  • How do I create resource to be injected with @Resource annotation

    I use @Resource get hold of DataSource or mail session in my session beans, but what am I supposed to do if i want to define my own resource, like org.apache.fop.apps.FopFactory? I only need to configure it and later access from my session beans like a resource, but I am not sure how do I do it. I guess I need to put it in the JNDI but what needs to be done with JBoss5 to do that? Is it java code or XML configuration?
    Thanks for any help!

    I've never really thought of custom resource injection before, but since no experienced developers are answering, here's some info I found:
    [Example 1 (in OpenEJB)|http://openejb.apache.org/3.0/custom-injection.html]
    Here's some code from [Web Tier to Go With Java EE 5: A Look at Resource Injection|http://java.sun.com/developer/technicalArticles/J2EE/injection/]
    private @Resource String welcomeMessage;
    public class HelloWorld extends HttpServlet {
         public void doGet(HttpServletRequest request,
                           HttpServletResponse response)
         throws ServletException, IOException {
             PrintWriter out = response.getWriter();
             out.println(welcomeMessage);
    <env-entry>
        <env-entry-name>welcomeMessage</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-name>
        <env-entry-value>Hello World from env-entry!</env-entry-value>
    </env-entry>You just need to discover where to put <env-entry>, but [this article|http://java.sun.com/developer/EJTechTips/2003/tt1209.html] and the first link will help you there.
    Also, maybe [this thread|http://forums.sun.com/thread.jspa?threadID=5176050] is useful (but I don't think so).

  • Ways to Get Resources in EJB

    Ways to Get Resources in EJB 3_
    source: http://javahowto.blogspot.com/2006/06/5-ways-to-get-resources-in-ejb-3.html
    Use resource injection with runtime info mapping.
    For example,
    package com.foo.ejb;
    import javax.ejb.Remote;
    @Remote public interface ResourceRemote {
    public void hello();
    package com.foo.ejb;
    import javax.annotation.Resource;
    import javax.ejb.Stateless;
    import javax.sql.DataSource;
    @Stateless
    public class ResourceBean implements ResourceRemote {
    @Resource(name="jdbc/employee")
    private DataSource employeeDataSource;You don't need ejb-jar.xml. For portable applications, you will need appserver-specific deployment plan to map the logical name (jdbc/employee) to the actual DataSource configured in the target runtime environment. For JavaEE SDK 5, Glassfish, and Sun Java System Application Server 9, it's sun-ejb-jar.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN"
    "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
    <sun-ejb-jar>
    <enterprise-beans>
    <ejb>
    <ejb-name>ResourceBean</ejb-name>
    *<jndi-name>ResourceBean</jndi-name>*
    <resource-ref>
      <res-ref-name>jdbc/employee</res-ref-name>
        <jndi-name>jdbc/__default</jndi-name>
    </resource-ref>
    </ejb>
    </enterprise-beans>
    </sun-ejb-jar>
    We have a tag like +<jndi-name>ResourceBean</jndi-name>+  in the above. Do we use this jndi-name ? If so, where ?

    user575089 wrote:
    Do we use this jndi-name ? If so, where ?If you need to look the bean up from JNDI?

  • How am I able to use an injected EJB in a Managed Bean Constructor?

    JSF 1.2
    EJB 3.0
    Glassfish v1
    Summary:
    Managed bean injected EJB is null when referencing EJB var in constructor.
    Details:
    In my managed bean, I have a constructor that tries to reference an injected EJB, such as:
    public class CustomerBean implements Serializable {
    @EJB private CustomerSessionRemote customerSessionRemote;
    public CustomerBean() {
    List<CustomerRow> results = customerSessionRemote.getCustomerList();
    }The call within the constructor to customerSessionRemote is null - I've double checked this in Netbeans 5.5.
    How am I able to use an injected EJB in a Managed Bean Constructor?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    OK, I was reading the article Web Tier to Go With Java EE 5: A Look at Resource Injection and I understand your statement too.
    Is there any way possible to Inject the EJB prior to the bean instance creation at all?
    Maybe, I need to approach it with the old fashion Java EE 1.4 route and using JNDI in the PostConstruct annotated method to reference the EJB in the managed bean.
    This had to been thought out before, I don't understand why a manged bean's life cycle places any injections at the end of the bean creation.
    Also, now that I understand that the @PostConstruct annotated method will be called by the container after the bean has been constructed and before any business methods of the bean are executed.
    I am trying to reference my EJB as part of the creation of the managed bean.
    What happens: the JSF page loads the managed bean and I need to populate a listbox component with data from an EJB.
    When I try to make the call to the EJB in the listbox setter method, the EJB reference is null.
    Now, I'm not for sure if the @PostConstruct annotation is going to work... hmmmm.
    ** Figured it out. ** I just needed to move the EJB logic that was still in the setter of the component I wanted to populate into the annotated PostConstruct method.

  • EntityManagerFactory injection problems

    I am continually getting the following error on the application server:
    Version = Sun Java System Application Server 9.1_01
    Running on an i86 machine with the Sun operating system installed. I do not seem to get this error on the windows version of the AS. This error was not happening, but started appearing for no apparent reason. It will inject the entity manager resource sometimes without a problem, then stop working. It is so irritating that I am thinking of getting rid of the AS altogether as I need a technology which is at least stable enough to give me reliable access to a database!
    Caused by: com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: AlexDb@Field-Injectable Resource. Class name = com.test.lis
    teners.ContextListener Field name=[email protected]@@@ into class com.test.listeners.ContextListener
    at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:387)
    at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:206)
    at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:117)
    at com.sun.web.server.WebContainerListener.injectInstance(WebContainerListener.java:180)
    at com.sun.web.server.WebContainerListener.containerEvent(WebContainerListener.java:125)
    ... 45 more
    Caused by: java.lang.IllegalArgumentException
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
    at java.lang.reflect.Field.set(Field.java:656)
    at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:338)
    ... 49 more

    Hi Frank,
    the doc:
    jsf-1_2-mrel-spec.pdf
    JavaServer™ Faces Specification
    Version 1.2 - Rev A
    Page - 169
    5.4 - Leveraging Java EE 5 Annotations in Managed Beans
    JSF Implementations that are running as a part of Java EE 5 must allow managed bean implementations to use the annotations specified in section 14.5 of the Servlet 2.5
    Specification to allow the container to inject references to container managed resources into
    a managed bean instance before it is made accessible to the JSF application. Only beans
    declared to be in request, session, or application scope are eligble for resource
    injection.
    Following is an example of valid usages of this feature in a managed bean
    public class User extends Object {
    private @EJB ShoppingCart cart;
    private @Resource Inventory inventory;
    private DataSource customerData;
    ....

  • JSP 2.1 - tag files annotation

    Hi,
    In JSP 2.1 spec is specified that tag handlers that implement javax.servlet.jsp.tagext.SimpleTag could be annotated : JSP.7.1.11 Resource Injection. Tag files when compiled extend javax.servlet.jsp.tagext.SimpleTagSupport which class implements javax.servlet.jsp.tagext.SimpleTag.
    So my question is can my tag file be injected?
    <%@ tag import="javax.annotation.*" extends="javax.servlet.jsp.tagext.SimpleTagSupport" %>
    <%!      
         private String completeInjection = "injectionIsNotComplete!";
         @InjectionComplete
         private void echoInjection(){
              completeInjection = "injection Is Complete!";
    %>
    completeInjection:<%= completeInjection %>Thanks,
    Todor

    OK, so the integrated run-time supports JSP 2.0 and tag files. But what I'm after is support in the design-time components. Specifically, I want to produce a set of user interface components that I can place in the component palette and have rendered in the JSP visual editor.
    As far as I can tell (see previous post), jDeveloper's editor doesn't understand JSP 2.0 features. Therefore I suspect that the design-time as a whole doesn't and so I'll have to use regular Java tags for anything that needs to be able to be rendered at design time.
    Oh well. Maybe I can write a Java tag implementation that somehow invokes a tag file and just write a simple wrapper taglib specifically for use within jDeveloper at design time.
    L.

Maybe you are looking for