struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Obinna <obi...@gmail.com>
Subject Re: Struts2SpringObjectFactory autowiring and injecting static property values when
Date Thu, 27 Aug 2009 06:12:20 GMT
I'd like to add a patch for this, but it's a bit more involved than I
initially expected so I'd like to get some feedback:

According to the Spring documentation:

    "Please also note that it is not currently possible to autowire
so-called *simple* properties such as primitives, Strings, and Classes (and
arrays of such simple properties). (This is by-design and should be
considered a *feature*.) When using either the *byType* or
*constructor*autowiring mode, it is possible to wire arrays and
typed-collections."

So to do this, what I'd like to do is to implement a new  BeanFactory
(extend DefaultListableBeanFactory) and override the autowireBean method to
call getBean() after autowiring which will inject these properties. However
there isone particular issue with this:

Since I can't really judge the impact of this change on legacy code, it
probably needs to be triggered by another! configuration option rather than
be the default implementation of the StrutsSpringObjectFactory. However, the
struts2-spring plugin already has the ClassReloadingBeanFactory which is
used for devMode. The question is how to combine both (and future factories
too?).  I was considering adding decoration to enable the chaining of
factories (the new factory would be a concrete decorator and contain the
ClassReloadingBeanFactory during dev mode), but I need to use some of the
methods in DefaultListableBeanFactory (getBeanNamesForType()), so my
decorator hierachy would have to be based on instances of
DefaultListableBeanFactory which doesn't seem right (and would have to
generate TONS of delegate methods just to use one).

Any ideas?

- Eric



2009/8/25 Musachy Barroso <musachy@gmail.com>

> Patches are always welcomed :)
>
> On Tue, Aug 25, 2009 at 3:59 AM, Obinna<obinna@gmail.com> wrote:
> > On Tue, Aug 25, 2009 at 1:55 PM, Obinna <obinna@gmail.com> wrote:
> >
> >>
> >>
> >>> ---------- Forwarded message ----------
> >>> From: Musachy Barroso <musachy@gmail.com>
> >>> To: Struts Users Mailing List <user@struts.apache.org>
> >>> Date: Mon, 24 Aug 2009 09:30:49 -0700
> >>> Subject: Re: Struts2SpringObjectFactory autowiring and injecting static
> >>> property values when
> >>> I can't remember for sure but there are few flags in the spring plugin
> >>> to configure autowiring.
> >>
> >>
> > Yeah, I'm aware of these, but haven't figured out a combination that does
> > what I want. Not sure there is one but wondering
> > if someone else had. If not, I'd advocate providing a patch as this can
> be
> > quite useful. FYI, the use case actually arose trying to use the
> > embedded-jsp
> > plugin to move an entire ui functional set (including its struts
> > configuration) into a shared jar .
> >
> > - Eric
> >
> >
> >>
> >>
> >>>
> >>> musachy
> >>>
> >>> On Mon, Aug 24, 2009 at 2:36 AM, Obinna<obinna@gmail.com> wrote:
> >>> > I'm using struts with the spring object factory
> >>> >
> >>> > I'm trying to package some struts configuration such that I can
> define
> >>> some
> >>> > commonly reused actions in a base struts configuration file and
> extend
> >>> in
> >>> > multiple projects. This means that my struts configuration will be
> >>> generic
> >>> > but my spring configuration (which I use to inject project-specific
> >>> > properties and other beans in to my action) will be project specific.
> >>> >
> >>> > In this base struts configuration, since I can't predict what the
> struts
> >>> > action beans will be named in the project-specific spring
> configuration
> >>> > file, I need to provide the full class name for each action. However,
> >>> when
> >>> > used in a project (which extends this base struts configuration), I
> >>> would
> >>> > like to be able to inject properties into this action from my spring
> >>> > configuration. In my spring configuration, I provide a bean entry for
> >>> the
> >>> > struts action and inject some other bean references and some static
> >>> > properties. Using the default autowiring strategy, upon instantiation
> of
> >>> the
> >>> > action (prototype scope), the spring object factory recognizes the
> >>> spring
> >>> > configuration for the action and "autowires" it to inject ONLY THE
> OTHER
> >>> > BEAN REFERENCES. ANY STATIC PROPERTIES SET IN CONFIGURATION ARE
> IGNORED.
> >>> > Looking through the spring code, this is due to the standard
> >>> implementation
> >>> > of the the autowireByName()  method being called in Spring's
> >>> > AbstractAutowireCapableBeanFactory class.
> >>> >
> >>> > My question: Is there currently some combination of spring wiring
> >>> > strategies/ struts configuration that will allow me to do what I want
> >>> which
> >>> > is to define my struts action by Class name and yet manage it it
> fully
> >>> > (including static-property injection) from my spring configuration
> file?
> >>> I
> >>> > suspect others will have run in to this same issue before.
> >>> >
> >>> > Thanks,
> >>> > - Eric
> >>> >
> >>>
> >>>
> >>>
> >>> --
> >>> "Hey you! Would you help me to carry the stone?" Pink Floyd
> >>>
> >>
> >>
> >
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message