struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: XWork injection intermittently skipped
Date Wed, 18 Sep 2013 23:59:30 GMT
  


> From: patrick.savage@3pillarglobal.com
> To: user@struts.apache.org
> Subject: XWork injection intermittently skipped
> Date: Wed, 18 Sep 2013 16:08:25 -0400
> 
> We are using XWork's @Inject in Struts 2.3.1.2 to inject a
> DefaultObjectTypeDeterminer into a custom type converter. Since upgrading
> from Java 1.6.0_33 to 1.7.0_25, this injection does not occur about half the
> time. The other @Inject we use (injecting a ValidatorFactory into a custom
> ActionValidatorManager configured by struts.actionValidatorManager in
> struts.xml) is still always working. There are no log messages at any log
> level that indicate a problem. The container successfully creates the custom
> type converter bean as evidenced by the log message
> "java.util.List:com.candyland.web.converters.CandylandCollectionConverter
> [treated as TypeConverter
> com.candyland.web.converters.CandylandCollectionConverter@245f96b0]".
 
MG>doubtful if @Inject works all of the time for ValidatorFactory then only some of the
time for CollectionConverter
MG>then the inconsistent behaviour is not from Inject but DefaultObjectTypeDeterminer

> Is it possible that this problem occurs because the getDeclaredMethods
> method in Java 7 no longer returns methods in a consistent order
> (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7023180)?. Per
> https://groups.google.com/forum/#!topic/google-guice/rQD5L2O-Po8, this
> causes Guice to inject objects in an inconsistent order so presumably the
MG>Inject is not guice but com.opensymphony.xwork2.inject.Inject
MG>(perhaps you're thinking of Spring?)

> Struts container would do the same, but I don't know if that would have any
> negative effects.
> 
> This is the relevant code:
> xwork-conversion.properties:
> 
> 
> java.util.List=com.candyland.web.converters.CandylandCollectionConverter
> ...
> 
> CandylandCollectionConverter.java:
> 
> public class CandylandCollectionConverter extends
> XWorkBasicConverter {
> private ObjectTypeDeterminer objectTypeDeterminer;
> 
> @Inject
> public void setObjectTypeDeterminer(ObjectTypeDeterminer
> det) {
> this.objectTypeDeterminer = det;
> super.setObjectTypeDeterminer(det);
> }
> ...
> }
> 
> As a workaround, we lazily get the DefaultObjectTypeDeterminer by calling
> Dispatcher.getInstance().getContainer().getInstance(ObjectTypeDeterminer.cla
> ss). This seems to be a reasonable workaround, but is there a way to fix the
> injection?
MG>then your injection happens at last minute when object is referenced instead of class
init?
MG>If you desire finer grained control of when objects will be created maybe you will consider
Spring AOP ..
MG>with Guice.createInjector...at least you will have more fine grained control WHEN
MG>your objects are created (before main execute(), during execute() or after execute()
)
http://blog.japila.pl/2011/01/abstractmodule-bindconstant-inject-and-named-in-google-guice/

> --
> Patrick
MG>Martin

> 
> ---------------------------------------------------------------------
> 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