geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: [xbean] annotation based dependency injection
Date Wed, 05 Apr 2006 09:30:27 GMT
On 4/5/06, David Blevins <> wrote:
> On Apr 4, 2006, at 11:37 PM, James Strachan wrote:
> > On 4/4/06, David Blevins <> wrote:
> >>
> >> On Apr 3, 2006, at 5:12 AM, James Strachan wrote:
> >>
> >>>> so I'm sure the XBean/OpenEJB folks will be implementing this
> >>> anyway.
> >>>
> >>> I'm not yet at that point in understanding what Dave B. has already
> >>> done in OpenEJB 3, but you're right it will be of high priority to
> >>> implement.
> >>>
> >>> Agreed. Adding support for AnDI into XBean would be pretty easy
> >>> then OpenEJB could reuse that. I ultimately want the entire
> >>> Geronimo kernel to support AnDI; whether you use EJB3 or not.
> >>
> >> Trick is the @Resource annotation can't be used to annotate a
> >> constructor.
> >>
> >> Know anyone on JSR 250 who'd propose changing that?
> >
> > Good point - though before JSR 250 & EJB 3, when Pico was just
> > starting, I tended to use the convention that contructor arguments
> > were 'mandatory' properties and setter methods were for optional stuff
> > (or stuff that can be configured after construction).
> >
> > i.e.  its kinda implicit that any constructor arguments must be
> > injected to be able to construct the object - so they are mandatory
> > already. I guess a container could shove in null objects or zero
> > values if it can't find a value, but maybe its easier to just say that
> > for constructor injection, the parameters should be considered
> > mandatory?
> I get it -- you're using @Resource to imply whether or not an object
> attribute is optional or required.

Yeah; Ideally there would be an @Mandatory in JSR 250 on properties...

> We're talking about different
> things then.  Was more going after EJB 3 perspective where @Resource
> is primarily used to label an object attribute with an identifier and
> optional mapping the injector understands (such as a jndi name, an
> xml attribute or element name, or whatever).

Yeah. Though the EJB 3 injection is more like auto-JNDI lookup; the
POJO is kinda pulling resources into itself using the name it defines.
In Spring style, the XML config injects into the POJO without its
particular pre-knowledge. So AnDI is a little attempt to reclaim the
@Resource annotation for non-JNDI style injection where we can just
use it as a marker for what are the mandatory properties.

Incidentally if you are considering mapping of properties to XML; then
the JAXB 2 annotations are way more flexible and have better
semantics. e.g. @XmlAttribute, @XmlElement - along with all the
namespace stuff together with things like @XmlID, @XmlIDRef and a ton
of other stuff.

> Seems like in your scenario, someone couldn't use the annotation to
> specify how object attribute would be populated via an injectable
> resource but still let it be an optional dependency.  Guessing you
> don't really care though :)

This is a good point. I'd assumed in EJB 3 land that @Resource implies
mandatory injection; what happens if there is no value available in
JNDI? Is that an error or is null used? If its the latter then maybe
we do need a @Mandatory or @NotNull or something.



View raw message