You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bruce Lombardi <br...@gmail.com> on 2014/04/02 18:43:47 UTC

Spring bean not injected into class extending WebApplication

I have an application that is integrated with Spring and a new requirement
is forcing me to update user login status for all users on  application
restart.

I want  to do this using  Springs JdbcOperations to do a simple execute of a
sql statement since Spring and Spring JPA are used throughout the
application.

The Application's init() method seems like a good place to do it since that
method runs whenever the application is started.

The problem I ran into is that my JdbcOperations instance is not injected
into the Application class instance so the init method throws a null pointer
exception.

I am able to inject JdbcOperations and lots of other things in my web pages,
but apparently, Spring has not yet been initialized when the Application's
init method is called. I suppose I could do something outside of Spring, but
that would make it inconsistent with the rest of the application.

Does anybody have any idea how to work around this? Is there any other place
later in the lifecycle of starting the application where I could do this?

 

Thanks,

Bruce


RE: Spring bean not injected into class extending WebApplication

Posted by Bruce Lombardi <br...@gmail.com>.
Thanks Martin. 
	I tried the first approach and it worked fine!
Bruce

-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org] 
Sent: Wednesday, April 02, 2014 12:56 PM
To: users@wicket.apache.org
Subject: Re: Spring bean not injected into class extending WebApplication

Hi,

One way is to use SpringWebApplicationFactory, i.e. init-param "applicationFactoryClassName". See its javadoc. It will allow you to use @SpringBean/Inject in YourApplication.java.
Another way is something like:
https://github.com/nextreports/nextreports-server/blob/master/src/ro/nextreports/server/web/NextServerApplication.java#L224

Martin Grigorov
Wicket Training and Consulting


On Wed, Apr 2, 2014 at 6:43 PM, Bruce Lombardi <br...@gmail.com> wrote:

> I have an application that is integrated with Spring and a new 
> requirement is forcing me to update user login status for all users on  
> application restart.
>
> I want  to do this using  Springs JdbcOperations to do a simple 
> execute of a sql statement since Spring and Spring JPA are used 
> throughout the application.
>
> The Application's init() method seems like a good place to do it since 
> that method runs whenever the application is started.
>
> The problem I ran into is that my JdbcOperations instance is not 
> injected into the Application class instance so the init method throws 
> a null pointer exception.
>
> I am able to inject JdbcOperations and lots of other things in my web 
> pages, but apparently, Spring has not yet been initialized when the 
> Application's init method is called. I suppose I could do something 
> outside of Spring, but that would make it inconsistent with the rest 
> of the application.
>
> Does anybody have any idea how to work around this? Is there any other 
> place later in the lifecycle of starting the application where I could 
> do this?
>
>
>
> Thanks,
>
> Bruce
>
>


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


Re: Spring bean not injected into class extending WebApplication

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

One way is to use SpringWebApplicationFactory, i.e. init-param
"applicationFactoryClassName". See its javadoc. It will allow you to use
@SpringBean/Inject in YourApplication.java.
Another way is something like:
https://github.com/nextreports/nextreports-server/blob/master/src/ro/nextreports/server/web/NextServerApplication.java#L224

Martin Grigorov
Wicket Training and Consulting


On Wed, Apr 2, 2014 at 6:43 PM, Bruce Lombardi <br...@gmail.com> wrote:

> I have an application that is integrated with Spring and a new requirement
> is forcing me to update user login status for all users on  application
> restart.
>
> I want  to do this using  Springs JdbcOperations to do a simple execute of
> a
> sql statement since Spring and Spring JPA are used throughout the
> application.
>
> The Application's init() method seems like a good place to do it since that
> method runs whenever the application is started.
>
> The problem I ran into is that my JdbcOperations instance is not injected
> into the Application class instance so the init method throws a null
> pointer
> exception.
>
> I am able to inject JdbcOperations and lots of other things in my web
> pages,
> but apparently, Spring has not yet been initialized when the Application's
> init method is called. I suppose I could do something outside of Spring,
> but
> that would make it inconsistent with the rest of the application.
>
> Does anybody have any idea how to work around this? Is there any other
> place
> later in the lifecycle of starting the application where I could do this?
>
>
>
> Thanks,
>
> Bruce
>
>