struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ivan Perales M." <>
Subject Using Spring parentContext to inject common dependencies is injecting dont expected values
Date Sat, 17 Mar 2012 18:46:46 GMT
Hello list, first of all thanks for your efforts trying to help noobs like

This is the first time i am using struts, more precise struts 2 and spring
plugin. I also am setting a parent context for common beans in various
wars. My problem is as follows:

As i have read, struts only works with autowired context, dont know why but
it's ok. My common beans have an id of the form
com.mycompany.bsi.ServiceBsi, so i can not use autowired by name because i
can not name a variable like that. So i am using autowired by type. The
problem represented here is an instantiation of an Action object by spring

I have done many test, but what i observed is that no matter if i use
@Autowired annotation or @Resource or none on a field, spring always inject
beans if there is a method with a param type of any existing bean. If the
method does not exists, event if field with annotation does, spring does
not inject the bean. That's for a side, in the another one, the method
AbstractAutowireCapableBeanFactory.unsatisfiedNonSimpleProperties wich is
called from  AbstractAutowireCapableBeanFactory.autowireByType, return an
array of Strings of the targets properties to be injected, but the weird
thing (maybe not) is that array contains properties like actionErrors,
actionMessages, fieldErrors who are part of the validationAware, not in the
action itselft. So for some rare circumstances of life, i have declared in
the parent context various list of LinkedList type, so for a reason unknown
for me, spring if transforming these lists into a map, putting the id of
the bean as a key, and injecting the resulted map into the method
fieldErrors, because this is expecting a Map<String, List<String>>, then
when the action is been invoked, there are errors and you can imagine what

I tried to use autowired by name, but nothing is injected, even if i use
@Resource instead of @Autowired. I tried to put the ref in the bean
declaration but the same, nothing injected.

I could resolve it by interfacing ApplicationContextAware on every action,
and the context is injected, but i'd like to inject only properties, not
the whole context. Moreover i know that the generation of the properties to
be injected when i use autowired by type is spring guilt, but i'd like to
know if there is a work arounf to solve this.

OK, thanks in advance for your time.

PD, sorry for my english.

Lindolfo Iván Perales Mancinas
Solo existen 10 tipos de personas en el mundo, las que saben binario y las
que no.

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