You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Security Management <li...@secmgmt.com> on 2009/03/06 17:20:18 UTC

Error autowiring an interface

So, I have a jsp form that uses:

<s:textfield name="user.name"/> and things like that.

The action's method for getUser provides an IUser (an interface).

The instantiated class is provided by a dao provider injected by Spring, but
all the jsp sees is the IUser type.

Now, it works great getting the form generated, but when submitting, I get:

2009-03-06 10:54:48,315 [http-8080-Processor24] ERROR
com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler - Could not
create and/or set value back on to object
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'com.blah.auth.IUser': Could not resolve matching constructor
	at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstr
uctor(ConstructorResolver.java:238)

Any suggestions?  Google is not helpful, strangely enough.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Error autowiring an interface

Posted by dusty <du...@yahoo.com>.
You can't do what you are doing exactly.  When you are using the "free"
conversion, Struts2 needs to be able to construct your object with a default
constructor and that is not going to happen with an interface.   So if you
want to dynamically determine the implementation of that Object at runtime
then you should look into the ModelDriven interceptor.

When your action implements ModelDriven you implement a method called
getModel() which returns the implementation you want.  It returns an Object
but struts will use reflection to find the getters you want from the posted
request.  In your form you just use name="name" rather than
name="user.name".

In getModel() you can do things like lookup a Spring managed bean based on a
String or whatever factory methodology you want.  




Security Management wrote:
> 
> So, I have a jsp form that uses:
> 
> <s:textfield name="user.name"/> and things like that.
> 
> The action's method for getUser provides an IUser (an interface).
> 
> The instantiated class is provided by a dao provider injected by Spring,
> but
> all the jsp sees is the IUser type.
> 
> Now, it works great getting the form generated, but when submitting, I
> get:
> 
> 2009-03-06 10:54:48,315 [http-8080-Processor24] ERROR
> com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler - Could
> not
> create and/or set value back on to object
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean
> with name 'com.blah.auth.IUser': Could not resolve matching constructor
> 	at
> org.springframework.beans.factory.support.ConstructorResolver.autowireConstr
> uctor(ConstructorResolver.java:238)
> 
> Any suggestions?  Google is not helpful, strangely enough.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-autowiring-an-interface-tp22375567p22391096.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org