You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Per Newgro <pe...@gmx.ch> on 2008/06/15 15:31:25 UTC

Spring - InjectorHolder has not been assigned an injector

Hi *,

i've read almost every thread in mailing list or wiki but i can't get my stuf 
to work. I derived my application layout from Igors++ phone book example. SO 
far it was pretty easy. The daos have been injected via @SpringBean in the 
page. Because i had some business logic and i don't want it in my pages, i've 
externalized it into an usecase class. Until now i've delivered the daos to 
the usecase while calling the method (doMyStuff(myDao)). So far so good. 

My next step was to externalize the daos. They should be injected in my 
usecase. But they wasn't. So i've read the threads an came up with

public MyUsecase() {
  InjectorHolder.getInjector().inject(this);
}

but now i get 

ERROR - log                        - Failed startup of context 
org.mortbay.jetty.webapp.WebAppContext@1343ed0{/,src/main/webapp}
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'myUC' defined in class path resource [usecases.xml]: Instantiation 
of bean failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Could not instantiate 
bean class [org.tipchamp.usecase.MyUsecase]: Constructor threw exception; 
nested exception is java.lang.IllegalStateException: InjectorHolder has not 
been assigned an injector. Use InjectorHolder.setInjector() to assign an 
injector. In most cases this should be done once inside SpringWebApplication 
subclass's init() method.
Caused by: 
org.springframework.beans.BeanInstantiationException: Could not instantiate 
bean class [org.tipchamp.usecase.MyUsecase]: Constructor threw exception; 
nested exception is java.lang.IllegalStateException: InjectorHolder has not 
been assigned an injector. Use InjectorHolder.setInjector() to assign an 
injector. In most cases this should be done once inside SpringWebApplication 
subclass's init() method.
Caused by: 
java.lang.IllegalStateException: InjectorHolder has not been assigned an 
injector. Use InjectorHolder.setInjector() to assign an injector. In most 
cases this should be done once inside SpringWebApplication subclass's init() 
method.
	at 
org.apache.wicket.injection.web.InjectorHolder.getInjector(InjectorHolder.java:64)
	at org.tipchamp.usecase.MyUsecase.<init>(MyUsecase.java:50)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

Can someone push me out here please?
Thanks
Per

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Spring - InjectorHolder has not been assigned an injector

Posted by Per Newgro <pe...@gmx.ch>.
Hi Timo Rantalaiho:
> This is fine in normal UI layer pojo classes that you
> construct with "new" operator in your own code during the
> execution of the application.  But in Spring-managed beans
> you should get your dependencies in with the normal Spring
> mechanisms (@Resource, autowiring or in XML as what you
> posted). Wicket should not be used in them.
>
> By the way, I strongly recommend a domain-driven design,
> with domain logic in the domain objects, instead of the
> proceduralish / model2-actionish usecases.
>
> Best wishes,
> Timo

omg, thanks for pushing me. I realy thaught SpringBean is a spring class, but 
it's a wicket class. Shame on me :-(

Thanks for the clearification. I will go on with integration.
Per

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Spring - InjectorHolder has not been assigned an injector

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Sun, 15 Jun 2008, Per Newgro wrote:
> page. Because i had some business logic and i don't want it in my pages, i've 
> externalized it into an usecase class. Until now i've delivered the daos to 
> the usecase while calling the method (doMyStuff(myDao)). So far so good. 
> 
> My next step was to externalize the daos. They should be injected in my 
> usecase. But they wasn't. So i've read the threads an came up with
> 
> public MyUsecase() {
>   InjectorHolder.getInjector().inject(this);
> }

This is fine in normal UI layer pojo classes that you
construct with "new" operator in your own code during the
execution of the application.  But in Spring-managed beans
you should get your dependencies in with the normal Spring
mechanisms (@Resource, autowiring or in XML as what you
posted). Wicket should not be used in them.
 
By the way, I strongly recommend a domain-driven design,
with domain logic in the domain objects, instead of the
proceduralish / model2-actionish usecases.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org