Injecting Resource Dependency into a Class Non-Injected EJB 3.0 Resource Reference Annotations
4.1.3 Declaring JMS Destinations and Connection Factories using Annotations
WebLogic Server 10.0 and higher releases support the EJB 3.0 programming model which uses annotations to configure metadata, eliminating the need for deployment descriptors. You can declare JMS objects using the Resources annotation as described in “Standard JDK Annotations Used By EJB 3.0” in Programming WebLogic Enterprise JavaBeans, Version 3.0 for Oracle WebLogic Server.4.1.3.1 Injecting Resource Dependency into a Class
If you apply Resource to a class, the resource is made available in the compenv context. The following is an example of how to inject a WebLogic JMS destination and connection factory resource in a JEE application, including EJBs, MDBs, and servlets. The following is a Wrapped JMS Pooling Annotation example: Example 4–1 Wrapped JMS Pooling Annotation Example . . . The name= or type= are not always required, mappedName= is usually sufficient. Resourcename=ReplyQueue, type=javax.jms.Queue.class, mappedName=jmsReplyQueue Destination rq; . . . Resourcename=ReplyConnectionFactory, type=javax.jms.ConnectionFactory.class, mappedName = jmsConnectionFactory ConnectionFactory cf; . . .4.1.3.2 Non-Injected EJB 3.0 Resource Reference Annotations
Injected resource dependencies are resolved when the host EJB or Servlet is instantiated. This is sometimes undesirable because: ■ The injection may prevent applications from deploying successfully if the container attempts to resolve references during deployment. ■ You might want to defer reference resolution until the application is first invoked. One way to setup a non-injected resource reference is to place a Resources annotation above the class definition. An application can resolve such references at runtime by looking up the reference in the bean context. As a best practice, the bean or servlet should also cache the result in order to avoid the overhead of repeated lookups. For example: Example 4–2 Non-Injected Resource Example . . . Resources { Resourcename=targetCFRef, mappedName=TargetCFJNDIName, 4-6 Programming JMS for Oracle WebLogic Server type=javax.jms.ConnectionFactory.class, Resourcename=targetDestRef, mappedName=TargetDestJNDIName, type=javax.jms.Destination.class } StatelessmappedName=StatelessBean public class MyStatelessBean implements MyStateless { Resource private SessionContext sctx; inject the bean context private ConnectionFactory targetCF; private Destination targetDest; public void completeWorkOrder { Lookup the JMS resources and cache for re-use. Note that a java:compenv prefix isnt needed for EJB3.0 bean contexts. if targetCF == null targetCF = javax.jms.ConnectionFactorysctx.lookuptargetCFRef; if targetDest == null targetDest = javax.jms.Destinationsctx.lookuptargetDestRef; . . . For a full example, see Chapter 4.6.4, EJB 3.0 Wrapper Without Injection.4.1.4 Avoid Transactional XA Interfaces
Parts
» Oracle Fusion Middleware Online Documentation Library
» Document Scope and Audience Guide to this Document
» Related Documentation New and Changed JMS Features In This Release
» Major Components WebLogic JMS Architecture
» Point-to-Point Messaging PublishSubscribe Messaging
» Using the Default Connection Factories
» Connection Understanding the JMS API
» WebLogic JMS Session Guidelines Session Subclasses Non-Transacted Session
» MessageProducer and MessageConsumer Understanding the JMS API
» Message Header Fields Message
» Message Property Fields Message
» ServerSessionPoolFactory ServerSessionPool ServerSession Understanding the JMS API
» ConnectionConsumer Understanding the JMS API
» Message Compression Message Properties and Message Header Fields Message Ordering
» Topics vs. Queues Asynchronous vs. Synchronous Consumers
» Persistent vs. Non-Persistent Messages
» Deferring Acknowledges and Commits Using AUTO_ACK for Non-Durable Subscribers
» Avoid Multi-threading Using the JMSXUserID Property
» Declaring a Wrapped JMS Factory using Deployment Descriptors
» Injecting Resource Dependency into a Class Non-Injected EJB 3.0 Resource Reference Annotations
» Automatically Enlisting Transactions Container-Managed Security
» Connection Testing Java EE Compliance Pooled JMS Connection Objects
» Speeding Up JNDI Lookups by Pooling Session Objects Speeding Up Object Creation Through Caching
» Performance and Tuning Disabling Wrapping and Pooling Simplified Access to Foreign JMS Providers
» ejb-jar.xml weblogic-ejb-jar.xml
» PoolTest.java PoolTestHome.java PoolTestBean.java
» Using compenv Sending a JMS Message In a Java EE Container
» Dependency Injection EJB 3.0 Wrapper Without Injection
» Create a Queue Session Create a Topic Session
» Create QueueSenders and QueueReceivers Create TopicPublishers and TopicSubscribers
» Step 1: Look Up a Connection Factory in JNDI Step 6a: Create the Message Object Message Producers
» Step 6b: Optionally Register an Asynchronous Message Listener
» Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7
» Send a Message Using Queue Sender
» Send a Message Using TopicPublisher
» Create a Message Object Define a Message Setting Message Producer Attributes
» Asynchronous Message Pipeline Receiving Messages Asynchronously
» Use Prefetch Mode to Create a Synchronous Message Pipeline
» Importing Required Packages Acknowledging Received Messages
» Setting a Redelivery Delay Overriding the Redelivery Delay on a Destination
» Defining a Session Exception Listener Closing a Session
» Preconditions for Deleting Destinations What Happens when a Destination is Deleted
» Defining the Persistent Store Setting the Client ID Policy
» Defining the Client ID Creating a Sharable Subscription Policy
» Creating Subscribers for a Durable Subscription Best Practice: Always Close Failed JMS ClientIDs
» Deleting Durable Subscriptions Modifying Durable Subscriptions
» Setting Message Header Fields
» Setting Message Property Fields
» Browsing Header and Property Fields
» Displaying Message Selectors Indexing Topic Subscriber Message Selectors To Optimize Performance
» WebLogic XML APIs Using a String Representation Using a DOM Representation
» Releasing Object Resources Configuring JMS System Resources Using JMSModuleHelper
» Creating a JMS System Resource Deleting a JMS System Resource
» Configuring JMS Servers and Store-and-Forward Agents Best Practices when Using JMSModuleHelper
» Benefits of Using Multicasting Limitations of Using Multicasting Using WebLogic Server Unicast
» Step 2: Set Up the Message Listener Dynamically Configuring Multicasting Configuration Attributes
» Uniform Distributed Destinations Weighted Distributed Destinations
» Queue Forwarding QueueSenders QueueReceivers
» TopicPublishers TopicSubscribers Using Replicated Distributed Topics
» Maximizing Production Stuck Messages
» Message Processing According to the JMS Specification Message Processing with Unit-of-Order
» Message Delivery with Unit-of-Order
» Joe Orders a Book What Happened to Joes Order
» Unit-of-Order and Distributed Topics Unit-of-Order, Topics, and Message Driven Beans
» Basic UOW Terminology Rules For Processing UOW Messages
» Example UOW Producer Code UOW Exceptions
» Limitations of UOW Message Groups Overview of Transactions
» WebLogic Messaging High Availability Features
» Application Design Limitations When using Replicated Distributed Topics Advanced Topic Features
» What is the Subscription Key Configuring a Shared Subscription
» Managing Durable Subscriptions How Sharing a Durable Subscription Works
» Sample Producer Code Re-usable ConnectionFactory Objects
» Re-usable Destination Objects Reconnected Connection Objects
» Reconnected Session Objects Automatic Failover for JMS Producers
» Special Cases for Reconnected Consumers
» Integer int Long long Character char String
» Closing Connections Helper Functions
Show more