|
From: Rod J. <rod...@in...> - 2004-06-24 16:20:45
|
Last night I committed two fairly significant enhancements to
the core IoC container.
1. Method Injection support. (Similar to what has been
described as "Getter Injection", but I believe that the
concept is more general and needs a more general name.) This
allows Spring to override abstract or concrete methods on
managed objects on deployment, to return the result of
looking up a named bean in the current factory. The lookup
will typically be of a non-singleton bean (although it can
also be a singleton).
This is useful when one object configured via Spring needs to
create instances of a non-singleton bean: for example, a
single-threaded, single-use processing object. E.g.
ThreadSafeService needs to create SingleShotHelper, which is
itself configured via DI. To date it was necessary for
ThreadSafeService to implement BeanFactoryAware, save the
BeanFactory reference and call
getBean("singleShotHelper")
each time it wanted to create a helper. That works fine, but
it's a Spring dependency, and we want a perfectly non-
invasive framework.
With the new functionality, it's possible to use an abstract
(or concrete) method such as
protected SingleShotHelper createSingleShotHelper()
and tell the container to override that method on deployment
to return a specific bean, like this:
<lookup-method name="createSingleShotHelper"
bean="singleShotHelper" />
The methods can be protected or public. Any number of methods
can be overridden.
This way there are no Spring dependencies. A corner case
closed off without needing to import a Spring API. This
feature was directly motivated by requirements in a client
project I'm working on.
Lookup methods can be combined with Setter Injection. They
can't presently be combined with Constructor Injection, but I
will add support for this, assuming that it's possible with
CGLIB.
The implementation uses CGLIB to subclass the class.
I've considered adding the ability to add arbitrary behaviour
in the overridden method--not just a bean lookup--and the
implementation allows this to be added fairly easily (I've
already prototyped it). However, I'm not convinced that the
more general case is an equally desirable feature. There are
other ways of doing this, such as subclassing the class and
overriding the method in the normal way, or using AOP. In the
case of the bean lookup, there is a very definite benefit in
the container doing the override, as it eliminates dependency
on a Spring API. It's also much simpler to describe in XML.
With the more general case, it's necessary to have a way of
identifying overloaded methods etc.
2. Support for creation of bean instances using static
factory methods, as an alternative to constructors. (Empty
JavaBean constructors or Constructor Injection constructors.)
This is potentially useful for legacy code. Joshua Bloch
advocates use of static factory methods in some cases instead
of constructors, and I'm sure many people have taken his
advice! (I doubt I would design new classes this way,
however.)
Arguments can be passed to the static factory methods using
<constructor-arg> elements. (None is required if the factory
method takes no arguments.)
This feature was motivated by the need to create AspectJ
aspects using the aspectOf() static factory method, but I
think it's a useful feature in general. See Adrian Colyer's
blog re AspectJ/Spring, at
http://www.aspectprogrammer.org/blogs/adrian/2004/05/what_the_
teache.html. This will be part of the AspectJ/Spring
integration in Spring 1.1. I think the potential for Spring
to configure AspectJ aspects using DI is very exciting.
The use of a factory method is specified by a new
optional "factory-method" attribute on the bean element. The
factory method must be on the class specified by the "bean"
attribute. This is normally, but not necessarily, the class
that is created by the factory method.
This can also be combined with Setter Injection.
Usage looks like this:
<bean id="whatever" class="whatever"
factory-method="createWhatever">
<constructor-arg index="0"><ref or value...
<property name="xxx"...
If the factory method is overloaded, the container will find
the correct one for the argument types.
Of course, these changes are backward compatible.
Rgds
Rod
|
|
From: <jue...@we...> - 2004-06-25 17:18:34
|
While this would be easy enough to add, I doubt that many people will = use it. IMHO, it feels a bit odd to first implement an interface that = specifies a setter and then still apply the property value via a = "property" key (which has to match the bean property of the setter in = the interface). =20 If we do magic anyway, why not assume that the injection interface = specifies a single method with a single parameter? We could then invoke = that method with the specified argument value. This would at least = remove the "property" redundancy. =20 I understand that this was the first way of IoC that XWork/WebWork2 = supported, but I'm not convinced that it is really recommendable. Feel = free to argue about that :-) =20 Juergen =20 ________________________________ Von: spr...@li... im Auftrag = von James Cook Gesendet: Fr 25.06.2004 15:40 An: spr...@li... Betreff: RE: [Springframework-developer] IoC container enhancements Since you are enhancing the injection support for the container, do you think it is worthwhile adding syntax to support Type 1 (Interface = Injection) IoC? http://opensource.atlassian.com/confluence/spring/display/DISC/Adding+Int= erf ace+Injection+to+Spring > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On = Behalf > Of Rod Johnson > Sent: Friday, June 25, 2004 3:50 AM > To: spr...@li... > Subject: Re: [Springframework-developer] IoC container enhancements > > > Lookup methods can be combined with Setter Injection. They > > can't presently be combined with Constructor Injection, but I > > will add support for this, assuming that it's possible with > > CGLIB. > > > I've just removed this restriction. > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: James C. <jim...@do...> - 2004-06-27 14:43:22
|
Well, I will argue it a bit :-) We use it to simplify the mapping of our DAO's to our web tier by making = our servlet actions implement a DAOAware interface. It is extremely = convenient to implement an interface and get the mapping for free. It is one step = more explicit than autowire-by-type which I like. (Too much magic on large projects can create very difficult to debug scenarios.) It helps = minimize the size of our Spring configuration, and it *works*. I'm too close to the solution to notice "any oddness" in its = configuration :-) Without some additional framework support, I don't see any other way = to do it now. The single property<->value relationship in that = configuration could be expanded to take a collection of property<->value relationships = in order to support multiple setters in a single interface. It's OK if you don't want to internalize it into the framework since it = is obviously supported now in some fashion. If you did come up with some = way to internalize it, perhaps it wouldn't get used much, I don't know. I know = our team greatly appreciates the convenience. > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On = Behalf > Of j=FCrgen h=F6ller [werk3AT] > Sent: Friday, June 25, 2004 1:19 PM > To: spr...@li... > Subject: Re: [Springframework-developer] IoC container enhancements >=20 > While this would be easy enough to add, I doubt that many people will = use > it. IMHO, it feels a bit odd to first implement an interface that > specifies a setter and then still apply the property value via a > "property" key (which has to match the bean property of the setter in = the > interface). >=20 > If we do magic anyway, why not assume that the injection interface > specifies a single method with a single parameter? We could then = invoke > that method with the specified argument value. This would at least = remove > the "property" redundancy. >=20 > I understand that this was the first way of IoC that XWork/WebWork2 > supported, but I'm not convinced that it is really recommendable. Feel > free to argue about that :-) >=20 > Juergen >=20 >=20 > ________________________________ >=20 > Von: spr...@li... im Auftrag = von > James Cook > Gesendet: Fr 25.06.2004 15:40 > An: spr...@li... > Betreff: RE: [Springframework-developer] IoC container enhancements >=20 >=20 >=20 > Since you are enhancing the injection support for the container, do = you > think it is worthwhile adding syntax to support Type 1 (Interface > Injection) > IoC? >=20 > = http://opensource.atlassian.com/confluence/spring/display/DISC/Adding+Int= e > rf > ace+Injection+to+Spring >=20 >=20 >=20 >=20 > > -----Original Message----- > > From: spr...@li... > > [mailto:spr...@li...] On = Behalf > > Of Rod Johnson > > Sent: Friday, June 25, 2004 3:50 AM > > To: spr...@li... > > Subject: Re: [Springframework-developer] IoC container enhancements > > > > > Lookup methods can be combined with Setter Injection. They > > > can't presently be combined with Constructor Injection, but I > > > will add support for this, assuming that it's possible with > > > CGLIB. > > > > > > I've just removed this restriction. > > > > > > > > ------------------------------------------------------- > > This SF.Net email sponsored by Black Hat Briefings & Training. > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > > digital self defense, top technical experts, no vendor pitches, > > unmatched networking opportunities. Visit www.blackhat.com > > _______________________________________________ > > Springframework-developer mailing list > > Spr...@li... > > = https://lists.sourceforge.net/lists/listinfo/springframework-developer >=20 >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer >=20 >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: Tom T. <tom...@pr...> - 2004-06-27 22:36:00
|
James,
What about a BeanPostProcessor?
For example:
public interface DaoAware {
public void setDao( Dao dao );
}
public class DaoAwareProcessor implements BeanPostProcessor,
InitializingBean {
Dao dao;
public void setDao( Dao dao ) {
this.dao =3D dao;
}
public void afterPropertiesSet() throws Exception {
if ( dao =3D=3D null ) {
throw new ApplicationContextException( "dao property must be
set on " + getClass() );
}
}
public Object postProcessBeforeInitialization( Object bean, String
name ) {
if ( bean instanceof DaoAware ) {
( ( DaoAware ) bean ).setDao( dao );
}
return bean;
}
public Object postProcessAfterInitialization( Object bean, String
name ) {
return bean;
}
}
Kind regards,
Tom.
On Sun, 27 Jun 2004 10:43:00 -0400, "James Cook"
<jim...@do...> said:
> Well, I will argue it a bit :-)
>=20
> We use it to simplify the mapping of our DAO's to our web tier by making
> our
> servlet actions implement a DAOAware interface. It is extremely
> convenient
> to implement an interface and get the mapping for free. It is one step
> more
> explicit than autowire-by-type which I like. (Too much magic on large
> projects can create very difficult to debug scenarios.) It helps minimize
> the size of our Spring configuration, and it *works*.
>=20
> I'm too close to the solution to notice "any oddness" in its
> configuration
> :-) Without some additional framework support, I don't see any other way
> to
> do it now. The single property<->value relationship in that configuration
> could be expanded to take a collection of property<->value relationships
> in
> order to support multiple setters in a single interface.
>=20
> It's OK if you don't want to internalize it into the framework since it
> is
> obviously supported now in some fashion. If you did come up with some way
> to
> internalize it, perhaps it wouldn't get used much, I don't know. I know
> our
> team greatly appreciates the convenience.
>=20
> > -----Original Message-----
> > From: spr...@li...
> > [mailto:spr...@li...] On Behalf
> > Of j=FCrgen h=F6ller [werk3AT]
> > Sent: Friday, June 25, 2004 1:19 PM
> > To: spr...@li...
> > Subject: Re: [Springframework-developer] IoC container enhancements
> >=20
> > While this would be easy enough to add, I doubt that many people will u=
se
> > it. IMHO, it feels a bit odd to first implement an interface that
> > specifies a setter and then still apply the property value via a
> > "property" key (which has to match the bean property of the setter in t=
he
> > interface).
> >=20
> > If we do magic anyway, why not assume that the injection interface
> > specifies a single method with a single parameter? We could then invoke
> > that method with the specified argument value. This would at least remo=
ve
> > the "property" redundancy.
> >=20
> > I understand that this was the first way of IoC that XWork/WebWork2
> > supported, but I'm not convinced that it is really recommendable. Feel
> > free to argue about that :-)
> >=20
> > Juergen
> >=20
> >=20
> > ________________________________
> >=20
> > Von: spr...@li... im Auftrag v=
on
> > James Cook
> > Gesendet: Fr 25.06.2004 15:40
> > An: spr...@li...
> > Betreff: RE: [Springframework-developer] IoC container enhancements
> >=20
> >=20
> >=20
> > Since you are enhancing the injection support for the container, do you
> > think it is worthwhile adding syntax to support Type 1 (Interface
> > Injection)
> > IoC?
> >=20
> > http://opensource.atlassian.com/confluence/spring/display/DISC/Adding+I=
nte
> > rf
> > ace+Injection+to+Spring
> >=20
> >=20
> >=20
> >=20
> > > -----Original Message-----
> > > From: spr...@li...
> > > [mailto:spr...@li...] On Beh=
alf
> > > Of Rod Johnson
> > > Sent: Friday, June 25, 2004 3:50 AM
> > > To: spr...@li...
> > > Subject: Re: [Springframework-developer] IoC container enhancements
> > >
> > > > Lookup methods can be combined with Setter Injection. They
> > > > can't presently be combined with Constructor Injection, but I
> > > > will add support for this, assuming that it's possible with
> > > > CGLIB.
> > >
> > >
> > > I've just removed this restriction.
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > digital self defense, top technical experts, no vendor pitches,
> > > unmatched networking opportunities. Visit www.blackhat.com
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=20
> >=20
> >=20
> >=20
> > -------------------------------------------------------
> > This SF.Net email sponsored by Black Hat Briefings & Training.
> > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > digital self defense, top technical experts, no vendor pitches,
> > unmatched networking opportunities. Visit www.blackhat.com
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=20
> >=20
> >=20
> >=20
> > -------------------------------------------------------
> > This SF.Net email sponsored by Black Hat Briefings & Training.
> > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > digital self defense, top technical experts, no vendor pitches,
> > unmatched networking opportunities. Visit www.blackhat.com
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
>=20
>=20
>=20
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> digital self defense, top technical experts, no vendor pitches,
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Tom T. <tom...@pr...> - 2004-06-28 06:05:57
|
Sorry, I only read your last mail, not the discussion in Confluence :$
Shouldn't send mails after midnight ;-)
Now that I've read it, I do agree with Juergen that an injection
interface having a single method with a single parameter would be
sufficient.
A single interface with multiple setters would probably be used to
combine DAO's often used together. I suppose you could just create an
interface extending several other interfaces with a single setter each
in that case?
Best regards,
Tom.
On Mon, 28 Jun 2004 00:35:55 +0200, "Tom Turelinckx"
<tom...@pr...> said:
> James,
>=20
> What about a BeanPostProcessor?
>=20
> For example:
>=20
> public interface DaoAware {
> public void setDao( Dao dao );
> }
>=20
> public class DaoAwareProcessor implements BeanPostProcessor,
> InitializingBean {
> Dao dao;
>=20
> public void setDao( Dao dao ) {
> this.dao =3D dao;
> }
>=20
> public void afterPropertiesSet() throws Exception {
> if ( dao =3D=3D null ) {
> throw new ApplicationContextException( "dao property must be
> set on " + getClass() );
> }
> }
>=20
> public Object postProcessBeforeInitialization( Object bean, String
> name ) {
> if ( bean instanceof DaoAware ) {
> ( ( DaoAware ) bean ).setDao( dao );
> }
> return bean;
> }
>=20
> public Object postProcessAfterInitialization( Object bean, String
> name ) {
> return bean;
> }
> }
>=20
> Kind regards,
> Tom.
>=20
> On Sun, 27 Jun 2004 10:43:00 -0400, "James Cook"
> <jim...@do...> said:
> > Well, I will argue it a bit :-)
> >=20
> > We use it to simplify the mapping of our DAO's to our web tier by making
> > our
> > servlet actions implement a DAOAware interface. It is extremely
> > convenient
> > to implement an interface and get the mapping for free. It is one step
> > more
> > explicit than autowire-by-type which I like. (Too much magic on large
> > projects can create very difficult to debug scenarios.) It helps minimi=
ze
> > the size of our Spring configuration, and it *works*.
> >=20
> > I'm too close to the solution to notice "any oddness" in its
> > configuration
> > :-) Without some additional framework support, I don't see any other way
> > to
> > do it now. The single property<->value relationship in that configurati=
on
> > could be expanded to take a collection of property<->value relationships
> > in
> > order to support multiple setters in a single interface.
> >=20
> > It's OK if you don't want to internalize it into the framework since it
> > is
> > obviously supported now in some fashion. If you did come up with some w=
ay
> > to
> > internalize it, perhaps it wouldn't get used much, I don't know. I know
> > our
> > team greatly appreciates the convenience.
> >=20
> > > -----Original Message-----
> > > From: spr...@li...
> > > [mailto:spr...@li...] On Beh=
alf
> > > Of j=FCrgen h=F6ller [werk3AT]
> > > Sent: Friday, June 25, 2004 1:19 PM
> > > To: spr...@li...
> > > Subject: Re: [Springframework-developer] IoC container enhancements
> > >=20
> > > While this would be easy enough to add, I doubt that many people will=
use
> > > it. IMHO, it feels a bit odd to first implement an interface that
> > > specifies a setter and then still apply the property value via a
> > > "property" key (which has to match the bean property of the setter in=
the
> > > interface).
> > >=20
> > > If we do magic anyway, why not assume that the injection interface
> > > specifies a single method with a single parameter? We could then invo=
ke
> > > that method with the specified argument value. This would at least re=
move
> > > the "property" redundancy.
> > >=20
> > > I understand that this was the first way of IoC that XWork/WebWork2
> > > supported, but I'm not convinced that it is really recommendable. Feel
> > > free to argue about that :-)
> > >=20
> > > Juergen
> > >=20
> > >=20
> > > ________________________________
> > >=20
> > > Von: spr...@li... im Auftrag=
von
> > > James Cook
> > > Gesendet: Fr 25.06.2004 15:40
> > > An: spr...@li...
> > > Betreff: RE: [Springframework-developer] IoC container enhancements
> > >=20
> > >=20
> > >=20
> > > Since you are enhancing the injection support for the container, do y=
ou
> > > think it is worthwhile adding syntax to support Type 1 (Interface
> > > Injection)
> > > IoC?
> > >=20
> > > http://opensource.atlassian.com/confluence/spring/display/DISC/Adding=
+Inte
> > > rf
> > > ace+Injection+to+Spring
> > >=20
> > >=20
> > >=20
> > >=20
> > > > -----Original Message-----
> > > > From: spr...@li...
> > > > [mailto:spr...@li...] On B=
ehalf
> > > > Of Rod Johnson
> > > > Sent: Friday, June 25, 2004 3:50 AM
> > > > To: spr...@li...
> > > > Subject: Re: [Springframework-developer] IoC container enhancements
> > > >
> > > > > Lookup methods can be combined with Setter Injection. They
> > > > > can't presently be combined with Constructor Injection, but I
> > > > > will add support for this, assuming that it's possible with
> > > > > CGLIB.
> > > >
> > > >
> > > > I've just removed this restriction.
> > > >
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > > digital self defense, top technical experts, no vendor pitches,
> > > > unmatched networking opportunities. Visit www.blackhat.com
> > > > _______________________________________________
> > > > Springframework-developer mailing list
> > > > Spr...@li...
> > > > https://lists.sourceforge.net/lists/listinfo/springframework-develo=
per
> > >=20
> > >=20
> > >=20
> > >=20
> > > -------------------------------------------------------
> > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > digital self defense, top technical experts, no vendor pitches,
> > > unmatched networking opportunities. Visit www.blackhat.com
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > >=20
> > >=20
> > >=20
> > >=20
> > > -------------------------------------------------------
> > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > digital self defense, top technical experts, no vendor pitches,
> > > unmatched networking opportunities. Visit www.blackhat.com
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=20
> >=20
> >=20
> >=20
> > -------------------------------------------------------
> > This SF.Net email sponsored by Black Hat Briefings & Training.
> > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > digital self defense, top technical experts, no vendor pitches,
> > unmatched networking opportunities. Visit www.blackhat.com
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
>=20
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> digital self defense, top technical experts, no vendor pitches,
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Tom T. <tom...@pr...> - 2004-06-28 06:27:49
|
Btw, I too prefer this over autowire-by-type in some cases and would
like it to be added, as it effectively provides control over both which
properties are autowired and which bean is wired to them.
Regards,
Tom.
On Mon, 28 Jun 2004 08:05:56 +0200, "Tom Turelinckx"
<tom...@pr...> said:
> Sorry, I only read your last mail, not the discussion in Confluence :$
> Shouldn't send mails after midnight ;-)
>=20
> Now that I've read it, I do agree with Juergen that an injection
> interface having a single method with a single parameter would be
> sufficient.
>=20
> A single interface with multiple setters would probably be used to
> combine DAO's often used together. I suppose you could just create an
> interface extending several other interfaces with a single setter each
> in that case?
>=20
> Best regards,
> Tom.
>=20
> On Mon, 28 Jun 2004 00:35:55 +0200, "Tom Turelinckx"
> <tom...@pr...> said:
> > James,
> >=20
> > What about a BeanPostProcessor?
> >=20
> > For example:
> >=20
> > public interface DaoAware {
> > public void setDao( Dao dao );
> > }
> >=20
> > public class DaoAwareProcessor implements BeanPostProcessor,
> > InitializingBean {
> > Dao dao;
> >=20
> > public void setDao( Dao dao ) {
> > this.dao =3D dao;
> > }
> >=20
> > public void afterPropertiesSet() throws Exception {
> > if ( dao =3D=3D null ) {
> > throw new ApplicationContextException( "dao property must be
> > set on " + getClass() );
> > }
> > }
> >=20
> > public Object postProcessBeforeInitialization( Object bean, String
> > name ) {
> > if ( bean instanceof DaoAware ) {
> > ( ( DaoAware ) bean ).setDao( dao );
> > }
> > return bean;
> > }
> >=20
> > public Object postProcessAfterInitialization( Object bean, String
> > name ) {
> > return bean;
> > }
> > }
> >=20
> > Kind regards,
> > Tom.
> >=20
> > On Sun, 27 Jun 2004 10:43:00 -0400, "James Cook"
> > <jim...@do...> said:
> > > Well, I will argue it a bit :-)
> > >=20
> > > We use it to simplify the mapping of our DAO's to our web tier by mak=
ing
> > > our
> > > servlet actions implement a DAOAware interface. It is extremely
> > > convenient
> > > to implement an interface and get the mapping for free. It is one step
> > > more
> > > explicit than autowire-by-type which I like. (Too much magic on large
> > > projects can create very difficult to debug scenarios.) It helps mini=
mize
> > > the size of our Spring configuration, and it *works*.
> > >=20
> > > I'm too close to the solution to notice "any oddness" in its
> > > configuration
> > > :-) Without some additional framework support, I don't see any other =
way
> > > to
> > > do it now. The single property<->value relationship in that configura=
tion
> > > could be expanded to take a collection of property<->value relationsh=
ips
> > > in
> > > order to support multiple setters in a single interface.
> > >=20
> > > It's OK if you don't want to internalize it into the framework since =
it
> > > is
> > > obviously supported now in some fashion. If you did come up with some=
way
> > > to
> > > internalize it, perhaps it wouldn't get used much, I don't know. I kn=
ow
> > > our
> > > team greatly appreciates the convenience.
> > >=20
> > > > -----Original Message-----
> > > > From: spr...@li...
> > > > [mailto:spr...@li...] On B=
ehalf
> > > > Of j=FCrgen h=F6ller [werk3AT]
> > > > Sent: Friday, June 25, 2004 1:19 PM
> > > > To: spr...@li...
> > > > Subject: Re: [Springframework-developer] IoC container enhancements
> > > >=20
> > > > While this would be easy enough to add, I doubt that many people wi=
ll use
> > > > it. IMHO, it feels a bit odd to first implement an interface that
> > > > specifies a setter and then still apply the property value via a
> > > > "property" key (which has to match the bean property of the setter =
in the
> > > > interface).
> > > >=20
> > > > If we do magic anyway, why not assume that the injection interface
> > > > specifies a single method with a single parameter? We could then in=
voke
> > > > that method with the specified argument value. This would at least =
remove
> > > > the "property" redundancy.
> > > >=20
> > > > I understand that this was the first way of IoC that XWork/WebWork2
> > > > supported, but I'm not convinced that it is really recommendable. F=
eel
> > > > free to argue about that :-)
> > > >=20
> > > > Juergen
> > > >=20
> > > >=20
> > > > ________________________________
> > > >=20
> > > > Von: spr...@li... im Auftr=
ag von
> > > > James Cook
> > > > Gesendet: Fr 25.06.2004 15:40
> > > > An: spr...@li...
> > > > Betreff: RE: [Springframework-developer] IoC container enhancements
> > > >=20
> > > >=20
> > > >=20
> > > > Since you are enhancing the injection support for the container, do=
you
> > > > think it is worthwhile adding syntax to support Type 1 (Interface
> > > > Injection)
> > > > IoC?
> > > >=20
> > > > http://opensource.atlassian.com/confluence/spring/display/DISC/Addi=
ng+Inte
> > > > rf
> > > > ace+Injection+to+Spring
> > > >=20
> > > >=20
> > > >=20
> > > >=20
> > > > > -----Original Message-----
> > > > > From: spr...@li...
> > > > > [mailto:spr...@li...] On=
Behalf
> > > > > Of Rod Johnson
> > > > > Sent: Friday, June 25, 2004 3:50 AM
> > > > > To: spr...@li...
> > > > > Subject: Re: [Springframework-developer] IoC container enhancemen=
ts
> > > > >
> > > > > > Lookup methods can be combined with Setter Injection. They
> > > > > > can't presently be combined with Constructor Injection, but I
> > > > > > will add support for this, assuming that it's possible with
> > > > > > CGLIB.
> > > > >
> > > > >
> > > > > I've just removed this restriction.
> > > > >
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > > > digital self defense, top technical experts, no vendor pitches,
> > > > > unmatched networking opportunities. Visit www.blackhat.com
> > > > > _______________________________________________
> > > > > Springframework-developer mailing list
> > > > > Spr...@li...
> > > > > https://lists.sourceforge.net/lists/listinfo/springframework-deve=
loper
> > > >=20
> > > >=20
> > > >=20
> > > >=20
> > > > -------------------------------------------------------
> > > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > > digital self defense, top technical experts, no vendor pitches,
> > > > unmatched networking opportunities. Visit www.blackhat.com
> > > > _______________________________________________
> > > > Springframework-developer mailing list
> > > > Spr...@li...
> > > > https://lists.sourceforge.net/lists/listinfo/springframework-develo=
per
> > > >=20
> > > >=20
> > > >=20
> > > >=20
> > > > -------------------------------------------------------
> > > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > > digital self defense, top technical experts, no vendor pitches,
> > > > unmatched networking opportunities. Visit www.blackhat.com
> > > > _______________________________________________
> > > > Springframework-developer mailing list
> > > > Spr...@li...
> > > > https://lists.sourceforge.net/lists/listinfo/springframework-develo=
per
> > >=20
> > >=20
> > >=20
> > >=20
> > > -------------------------------------------------------
> > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > digital self defense, top technical experts, no vendor pitches,
> > > unmatched networking opportunities. Visit www.blackhat.com
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=20
> >=20
> > -------------------------------------------------------
> > This SF.Net email sponsored by Black Hat Briefings & Training.
> > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > digital self defense, top technical experts, no vendor pitches,
> > unmatched networking opportunities. Visit www.blackhat.com
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
>=20
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> digital self defense, top technical experts, no vendor pitches,
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Oliver H. <Ol...@ou...> - 2004-06-27 23:11:48
|
I also believe that interface injection is a valid pattern and should be =
supported explicitly by the mapping docs. It seems a pity that Spring =
uses Type 1 under the covers (the Bean*Aware interfaces come to mind) =
but has no support for specifying custom interface injection.
Couldn't it be added quite simply through an extension of the root/child =
support?
With the current support you can do this:
<bean id=3D"org.whatever.Interface" class=3D"org.whatever.Interface">
<property name=3D"a"><value>1</value></property>
<property name=3D"b"><value>2</value></property>
</bean>
=20
<bean id=3D"implementingBean" class=3D"org.whatever.InterfaceImpl"
parent=3D"org.whatever.Interface" />
But would it be possible to implement a BeanFactoryPostProcessor that =
could detect any beans that implement org.whatever.Interface and =
automatically apply the parent attribute to them?=20
> -----Original Message-----
> From: spr...@li...=20
> [mailto:spr...@li...]
> On Behalf Of James Cook
> Sent: Monday, 28 June 2004 12:43 AM
> To: spr...@li...
> Subject: RE: [Springframework-developer] IoC container enhancements
>=20
>=20
> Well, I will argue it a bit :-)
>=20
> We use it to simplify the mapping of our DAO's to our web=20
> tier by making our servlet actions implement a DAOAware=20
> interface. It is extremely convenient to implement an=20
> interface and get the mapping for free. It is one step more=20
> explicit than autowire-by-type which I like. (Too much magic=20
> on large projects can create very difficult to debug=20
> scenarios.) It helps minimize the size of our Spring=20
> configuration, and it *works*.
>=20
> I'm too close to the solution to notice "any oddness" in its=20
> configuration
> :-) Without some additional framework support, I don't see=20
> any other way to do it now. The single property<->value=20
> relationship in that configuration could be expanded to take=20
> a collection of property<->value relationships in order to=20
> support multiple setters in a single interface.
>=20
> It's OK if you don't want to internalize it into the=20
> framework since it is obviously supported now in some=20
> fashion. If you did come up with some way to internalize it,=20
> perhaps it wouldn't get used much, I don't know. I know our=20
> team greatly appreciates the convenience.
>=20
> > -----Original Message-----
> > From: spr...@li...
> > [mailto:spr...@li...] On=20
> > Behalf Of j=FCrgen h=F6ller [werk3AT]
> > Sent: Friday, June 25, 2004 1:19 PM
> > To: spr...@li...
> > Subject: Re: [Springframework-developer] IoC container enhancements
> >=20
> > While this would be easy enough to add, I doubt that many=20
> people will=20
> > use it. IMHO, it feels a bit odd to first implement an=20
> interface that=20
> > specifies a setter and then still apply the property value via a=20
> > "property" key (which has to match the bean property of the=20
> setter in=20
> > the interface).
> >=20
> > If we do magic anyway, why not assume that the injection interface=20
> > specifies a single method with a single parameter? We could then=20
> > invoke that method with the specified argument value. This would at=20
> > least remove the "property" redundancy.
> >=20
> > I understand that this was the first way of IoC that XWork/WebWork2=20
> > supported, but I'm not convinced that it is really=20
> recommendable. Feel=20
> > free to argue about that :-)
> >=20
> > Juergen
> >=20
> >=20
> > ________________________________
> >=20
> > Von: spr...@li...=20
> im Auftrag=20
> > von James Cook
> > Gesendet: Fr 25.06.2004 15:40
> > An: spr...@li...
> > Betreff: RE: [Springframework-developer] IoC container enhancements
> >=20
> >=20
> >=20
> > Since you are enhancing the injection support for the container, do=20
> > you think it is worthwhile adding syntax to support Type 1=20
> (Interface
> > Injection)
> > IoC?
> >=20
> >=20
> http://opensource.atlassian.com/confluence/spring/display/DISC/Adding+
> > Inte
> > rf
> > ace+Injection+to+Spring
> >=20
> >=20
> >=20
> >=20
> > > -----Original Message-----
> > > From: spr...@li...
> > > [mailto:spr...@li...] On=20
> > > Behalf Of Rod Johnson
> > > Sent: Friday, June 25, 2004 3:50 AM
> > > To: spr...@li...
> > > Subject: Re: [Springframework-developer] IoC container=20
> enhancements
> > >
> > > > Lookup methods can be combined with Setter Injection.=20
> They can't=20
> > > > presently be combined with Constructor Injection, but I=20
> will add=20
> > > > support for this, assuming that it's possible with CGLIB.
> > >
> > >
> > > I've just removed this restriction.
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.Net email sponsored by Black Hat Briefings & Training.
> > > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > > digital self defense, top technical experts, no vendor pitches,
> > > unmatched networking opportunities. Visit www.blackhat.com
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > >=20
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=20
> >=20
> >=20
> >=20
> > -------------------------------------------------------
> > This SF.Net email sponsored by Black Hat Briefings & Training.
> > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > digital self defense, top technical experts, no vendor pitches,
> > unmatched networking opportunities. Visit www.blackhat.com
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> >=20
> https://lists.sourceforge.net/lists/listinfo/s> =
pringframework-developer
> >=20
> >=20
> >=20
> >=20
> > -------------------------------------------------------
> > This SF.Net email sponsored by Black Hat Briefings & Training.
> > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> > digital self defense, top technical experts, no vendor pitches,
> > unmatched networking opportunities. Visit www.blackhat.com
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> >=20
> https://lists.sourceforge.net/lists/listinfo/s> =
pringframework-developer
>=20
>=20
>=20
>=20
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20
> digital self defense, top technical experts, no vendor pitches,=20
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
|
|
From: Rod J. <rod...@in...> - 2004-06-25 09:05:55
|
> Lookup methods can be combined with Setter Injection. They > can't presently be combined with Constructor Injection, but I > will add support for this, assuming that it's possible with > CGLIB. I've just removed this restriction. |
|
From: James C. <jim...@do...> - 2004-06-25 13:40:18
|
Since you are enhancing the injection support for the container, do you think it is worthwhile adding syntax to support Type 1 (Interface Injection) IoC? http://opensource.atlassian.com/confluence/spring/display/DISC/Adding+Interf ace+Injection+to+Spring > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On Behalf > Of Rod Johnson > Sent: Friday, June 25, 2004 3:50 AM > To: spr...@li... > Subject: Re: [Springframework-developer] IoC container enhancements > > > Lookup methods can be combined with Setter Injection. They > > can't presently be combined with Constructor Injection, but I > > will add support for this, assuming that it's possible with > > CGLIB. > > > I've just removed this restriction. > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: Rod J. <rod...@in...> - 2004-06-25 16:54:02
|
James, I'll take another look at the Wiki page. Rgds Rod ----- Original Message ----- From: "James Cook" <jim...@do...> To: <spr...@li...> Sent: Friday, June 25, 2004 2:40 PM Subject: RE: [Springframework-developer] IoC container enhancements > Since you are enhancing the injection support for the container, do you > think it is worthwhile adding syntax to support Type 1 (Interface Injection) > IoC? > > http://opensource.atlassian.com/confluence/spring/display/DISC/Adding+Interf > ace+Injection+to+Spring |
|
From: Rod J. <rod...@in...> - 2004-06-28 11:56:44
|
To round out our Method Injection support, I've just added the ability for
the container to override a method to replace it with an arbitrary piece of
code, in an implementation of the MethodReplacer interface.
The XML syntax looks as follows:
<replaced-method name="doSomething"
replacer="beanNameOfReplacer">
</replaced-method>
This is a less commonly useful feature than lookup Method Injection, but it
has certain uses. For example, a protected setRollbackOnly method could be
overridden by the container to use the TransactionContext, avoiding Spring
dependencies in testing. I would envisage most of the usages, like this one,
involving a fairly generic, reusable MethodReplacer.
An example of what could be done: a getDataSource() method could be
overridden to return a transactional DataSource if there's an active
transaction, otherwise a read-only DataSource. Of course this kind of thing
can often be done with a custom TargetSource. However, there is a difference
here: Method Injection actually changes the class, so the class can invoke
methods on itself and get the new behaviour without going through a proxy.
I will try to put together examples and usage guidelines before 1.1 final is
released. If you're interested in the meantime, take a look at
XmlBeanFactoryTestSuite. I see Method Injection as very useful in a number
of corner cases, but not something to use without good reason.
Rgds
Rod
|