@Resource without type
yves.p Oct 12, 2011 4:48 PMI'm trying to inject a queue and a connectionfactory via @Resource field annotation into a servlet:
public class MDBSender extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { @Resource(name= "java:/queue/testQueue", type=javax.jms.Queue.class) private Queue queue; @Resource(name = "java:/jms/connectionFactory", type=javax.jms.ConnectionFactory.class) private ConnectionFactory jmsConnectionFactory;
If I don't specify the type in the annotation JBoss throws this exception:
21:21:40,897 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "MDBSender_war-0.0.1-SNAPSHOT. war" 21:21:40,897 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Replacement of deployment "MDBSender_war-0.0.1 -SNAPSHOT.war" by deployment "MDBSender_war-0.0.1-SNAPSHOT.war" was rolled back with failure message {"Failed services" => {"jboss .deployment.unit.\"MDBSender_war-0.0.1-SNAPSHOT.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deploymen t.unit.\"MDBSender_war-0.0.1-SNAPSHOT.war\".INSTALL: Failed to process phase INSTALL of deployment \"MDBSender_war-0.0.1-SNAPSHOT. war\""},"Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.\"MDBSender_war-0.0.1-SNAPSHOT\".\" MDBSender_war-0.0.1-SNAPSHOT\".ValidatorFactory missing [ jboss.naming.context.java.module.\"MDBSender_war-0.0.1-SNAPSHOT\".\"MDBS ender_war-0.0.1-SNAPSHOT\" ]","jboss.naming.context.java.module.\"MDBSender_war-0.0.1-SNAPSHOT\".\"MDBSender_war-0.0.1-SNAPSHOT\". Validator missing [ jboss.naming.context.java.module.\"MDBSender_war-0.0.1-SNAPSHOT\".\"MDBSender_war-0.0.1-SNAPSHOT\" ]"]} 21:21:40,959 WARN [org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor] (MSC service thread 1-3) Can' t handle @Resource for ENC name: java:/queue/testQueue on class ch.mobi.test.MDBSender.MDBSender since it's missing a "lookup" (or "mappedName") value and isn't of any known type 21:21:41,022 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit." MDBSender_war-0.0.1-SNAPSHOT.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."MDBSender_war-0. 0.1-SNAPSHOT.war".INSTALL: Failed to process phase INSTALL of deployment "MDBSender_war-0.0.1-SNAPSHOT.war" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7 .1.0.Alpha2-SNAPSHOT.jar:7.1.0.Alpha2-SNAPSHOT] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA .jar:1.0.1.GA] at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0. 1.GA] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_27] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_27] at java.lang.Thread.run(Thread.java:662) [:1.6.0_27] Caused by: java.lang.NullPointerException at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:232) at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:168) at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:52) at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.ja va:140) at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:133) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7 .1.0.Alpha2-SNAPSHOT.jar:7.1.0.Alpha2-SNAPSHOT] ... 5 more
Shouldn't it be able to figure out the type by itself? From the Java Doc of @Ressource:
http://download.oracle.com/javaee/6/api/javax/annotation/Resource.html#type%28%29
The Java type of the resource. For field annotations, the default is the type of the field. For method annotations, the default is the type of the JavaBeans property. For class annotations, there is no default and this must be specified.
I'm using a nightly build 7.1.0.Alpha2 1704
Edit:
With the type in the annotation a warning still appears in the log but the application deploys:
22:21:11,444 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "MDBSender_war-0.0.1-SNAPSHOT. war" 22:21:11,475 WARN [org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor] (MSC service thread 1-4) Can' t handle @Resource for ENC name: java:/queue/testQueue on class ch.mobi.test.MDBSender.MDBSender since it's missing a "lookup" (or "mappedName") value and isn't of any known type 22:21:11,506 INFO [org.jboss.web] (MSC service thread 1-2) registering web context: /MDBSender_war-0.0.1-SNAPSHOT 22:21:11,522 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Replaced deployment "MDBSender_war-0.0.1-SNAPS HOT.war" with deployment "MDBSender_war-0.0.1-SNAPSHOT.war"
and the queue is null.
The queue is definitly bound in jndi:
22:45:01,618 INFO [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-1) trying to deploy queue jms.queue.test Queue 22:45:01,634 INFO [org.jboss.as.connector] (MSC service thread 1-2) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.4.F inal) 22:45:01,665 INFO [org.jboss.as.messaging] (MSC service thread 1-1) JBAS011601: Bound messaging object to jndi name java:/queue/t estQueue 22:45:01,696 INFO [org.jboss.as.messaging] (MSC service thread 1-3) JBAS011601: Bound messaging object to jndi name java:/jms/con nectionFactory