Any issues using @SpringBean in WebApplication

View: New views
12 Messages — Rating Filter:   Alert me  

Any issues using @SpringBean in WebApplication

by shetc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

Are there any issues associated with using the @SpringBean annotation in a class that
inherits from WebApplication or AuthenticatedWebApplication?

Thanks,
Steve

Re: Any issues using @SpringBean in WebApplication

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

no

-igor

On Wed, Oct 28, 2009 at 1:22 PM, Steve Hiller <shetc@...> wrote:
> Hi All,
>
> Are there any issues associated with using the @SpringBean annotation in a class that
> inherits from WebApplication or AuthenticatedWebApplication?
>
> Thanks,
> Steve
>

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


Re: Any issues using @SpringBean in WebApplication

by shetc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Igor!

Re: Any issues using @SpringBean in WebApplication

by Pieter Degraeuwe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hmm,

I was always thinking that the @SpringBean annotation should be used in
Pages and/or components.
You should inject your dependencies in your Application directly in your
spring.xml.


your spring.xml should contain something like this:

    <bean class="foo.bar.MyApplication">
        <property name="googleMapsKey" value="${googlemaps.key}"/>
        <property name="myService" ref="service"/>
    </bean>

your web.xml contains then a reference to your Application bean

    <filter>
        <filter-name>wicket.fast-web</filter-name>

<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>

        <init-param>
            <param-name>applicationFactoryClassName</param-name>

<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
        </init-param>
   </filter>



On Wed, Oct 28, 2009 at 9:22 PM, Steve Hiller <shetc@...> wrote:

> Hi All,
>
> Are there any issues associated with using the @SpringBean annotation in a
> class that
> inherits from WebApplication or AuthenticatedWebApplication?
>
> Thanks,
> Steve
>



--
Pieter Degraeuwe
Systemworks bvba
Belgiƫlaan 61
9070 Destelbergen
GSM: +32 (0)485/68.60.85
Email: pieter.degraeuwe@...
visit us at http://www.systemworks.be

Re: Any issues using @SpringBean in WebApplication

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ah, woops. i misread "in" as "with"

you will have to inject the application class manually. after you
install the spring component injector.

-igor


On Wed, Oct 28, 2009 at 1:29 PM, shetc <shetc@...> wrote:

>
> Thanks Igor!
> --
> View this message in context: http://www.nabble.com/Any-issues-using-%40SpringBean-in-WebApplication-tp26101512p26101590.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

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


Re: Any issues using @SpringBean in WebApplication

by Michael O'Cleirigh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You could use the @Autowired Spring annotation and the  
autowire="byType" attribute to the bean definition to support autowiring
to get the same effect as @SpringBean brings in Components.

e.g.

  <bean class="foo.bar.MyApplication" autowire="byType" />


Regards,

Mike


>
> I was always thinking that the @SpringBean annotation should be used in
> Pages and/or components.
> You should inject your dependencies in your Application directly in your
> spring.xml.
>
>
> your spring.xml should contain something like this:
>
>     <bean class="foo.bar.MyApplication">
>         <property name="googleMapsKey" value="${googlemaps.key}"/>
>         <property name="myService" ref="service"/>
>     </bean>
>
> your web.xml contains then a reference to your Application bean
>
>     <filter>
>         <filter-name>wicket.fast-web</filter-name>
>
> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
>
>         <init-param>
>             <param-name>applicationFactoryClassName</param-name>
>
> <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
>         </init-param>
>    </filter>
>
>
>
> On Wed, Oct 28, 2009 at 9:22 PM, Steve Hiller <shetc@...> wrote:
>
>  
>> Hi All,
>>
>> Are there any issues associated with using the @SpringBean annotation in a
>> class that
>> inherits from WebApplication or AuthenticatedWebApplication?
>>
>> Thanks,
>> Steve
>>
>>    
>
>
>
>  


Re: Any issues using @SpringBean in WebApplication

by James Carman-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Oct 28, 2009 at 5:29 PM, Michael O'Cleirigh
<michael.ocleirigh@...> wrote:
> You could use the @Autowired Spring annotation and the Ā autowire="byType"
> attribute to the bean definition to support autowiring to get the same
> effect as @SpringBean brings in Components.

Not exactly, Michael.  The injected beans aren't a good candidate to
pass to pages/components that need to be serialized.  That's one of
the main reasons why we use @SpringBean.  If you're just going to use
the beans by looking them up through the application object, then it's
no big deal.  But, if they ever make their way into a page/component
as a field, then you'll have problems.

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


Re: Any issues using @SpringBean in WebApplication

by shetc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there an impact on performance if Spring beans are injected in a WebApplication and then shared for use in WebSession and WebPages (as opposed to injecting directly in WebSession and WebPages)?

Re: Any issues using @SpringBean in WebApplication

by Eelco Hillenius :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Is there an impact on performance if Spring beans are injected in a
> WebApplication and then shared for use in WebSession and WebPages (as
> opposed to injecting directly in WebSession and WebPages)?

Sharing them (just don't keep references in your components) should be
slightly more efficient. Not the kind of gain you should base your
decisions on imho though.

Eelco

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


Re: Any issues using @SpringBean in WebApplication

by shetc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Eelco -- My colleague and I were thinking that putting them all in the WebApplication
would make it easier to mock services for unit testing with WicketTester.

Eelco Hillenius wrote:
Sharing them (just don't keep references in your components) should be
slightly more efficient. Not the kind of gain you should base your
decisions on imho though.

Eelco

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

Re: Any issues using @SpringBean in WebApplication

by Eelco Hillenius :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Hi Eelco -- My colleague and I were thinking that putting them all in the
> WebApplication
> would make it easier to mock services for unit testing with WicketTester.

Alternatively, you could use e.g. InjectorHolder.setInjector(new
MockSpringInjector()); like is documented in
org.apache.wicket.injection.web.InjectorHolder (at least it is in
Wicket 1.3 which I am using). That's a bit more flexible and you don't
have to worry about cases where someone (colleague?) uses @SpringBean
directly and thus compromises your test strategy).

Eelco

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


Re: Any issues using @SpringBean in WebApplication

by shetc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, I get it! I'll give a try and let you know how I get on. Thanks!


Eelco Hillenius wrote:
Alternatively, you could use e.g. InjectorHolder.setInjector(new
MockSpringInjector()); like is documented in
org.apache.wicket.injection.web.InjectorHolder (at least it is in
Wicket 1.3 which I am using). That's a bit more flexible and you don't
have to worry about cases where someone (colleague?) uses @SpringBean
directly and thus compromises your test strategy).

Eelco

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