Forum Stats

  • 3,757,778 Users
  • 2,251,265 Discussions
  • 7,869,915 Comments

Discussions

Common annotation 1.1 on Javaee6

843830
843830 Member Posts: 47,913 Green Ribbon
edited Aug 10, 2011 12:33PM in Java Message Service (JMS)
import javax.annotation.Resource;
I try to use the following code for dependecy injection:

@Resource(lookup = "jms/javaee6/ConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "jms/javaee6/Queue")
private static Queue queue;

However, when I build with maven. The error message keeps showing
cannot find symbol
symbol : method lookup()
location: @interface javax.annotation.Resource

Anything i can do in order to make it works?

Thanks.

Comments

  • 805009
    805009 Member Posts: 122
    That's because "lookup" isn't a valid method on javax.annotation.Resource. Try "name".

    Nigel
  • 843830
    843830 Member Posts: 47,913 Green Ribbon
  • shelleyb
    shelleyb Member Posts: 9
    javax.annotation.Resource does include a "lookup" method as of Java EE 6.

    http://download.oracle.com/javaee/6/api/javax/annotation/Resource.html#lookup()
  • shelleyb
    shelleyb Member Posts: 9
    The problem with building this in Maven is that the JDK also includes a javax.annotation.Resource which does not yet include the "lookup" method -

    http://download.oracle.com/javase/6/docs/api/javax/annotation/Resource.html

    In order to get it to build with Maven, you will need to add the JAR containing the correct javax.annotation.Resource to an endorsed JAR. This can be done by using the maven-dependency-plugin to copy the JAR to a directory, and then configuring the compiler plugin to reference the endorsed dir: -Djava.endorsed.dirs=${project.build.directory}/endorsed.

    The following blog post includes more detailed information -
    http://jaitechwriteups.blogspot.com/2011/02/resource-and-new-lookup-attribute-how.html
  • Nigel Deakin-Oracle
    Nigel Deakin-Oracle Member Posts: 115
    edited Aug 10, 2011 12:33PM
    You're quite right, of course. @Resource(lookup="foo") is perfectly valid in Java EE 6, with several examples in the spec. Thanks for explaining why it doesn't always compile, even with Java EE 6 in the classpath.

    Nigel
This discussion has been closed.