Injecting A Spring Bean Into An Implementation Of IAuthorizationStrategy class

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

Injecting A Spring Bean Into An Implementation Of IAuthorizationStrategy class

by carlo c :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

we created an implementation of IAuthorizationStrategy class.
However, we need to access a spring managed object within that class?
How do I get it to use a spring bean?
@SpringBean annotation wouldn't work because it is not an instance of
a Component.

public class SampleAuthorizationStrategy implements IAuthorizationStrategy {

   ( we want to inject a spring bean into this)
    private HelloWorldService helloWorldService;
}



Thanks A Lot
Carlo

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


Re: Injecting A Spring Bean Into An Implementation Of IAuthorizationStrategy class

by Xavier López-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Carlo,

Just wire the spring bean like you would do with any other bean. Notice
you're almost on your own when implementing IAuthorizationStrategy (it
doesn't extend nothing else).

I did it with @Autowired annotation to inject a bean annotated with @Service
in its class, with Spring using context:component-scan for discovering
beans, and autowiring by name.

Cheers !

2009/11/5 Carlo Camerino <carlo.camerino@...>

> Hi,
>
> we created an implementation of IAuthorizationStrategy class.
> However, we need to access a spring managed object within that class?
> How do I get it to use a spring bean?
> @SpringBean annotation wouldn't work because it is not an instance of
> a Component.
>
> public class SampleAuthorizationStrategy implements IAuthorizationStrategy
> {
>
>   ( we want to inject a spring bean into this)
>    private HelloWorldService helloWorldService;
> }
>
>
>
> Thanks A Lot
> Carlo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>


--
"To err is human; to make real mess, you need a computer."

Re: Injecting A Spring Bean Into An Implementation Of IAuthorizationStrategy class

by reiern70 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The Java doc of SpringComponentInjector recommends using

InjectorHolder.getInjector().inject(this);

on the constructor of Non-wicket components (e.g. Sessions, Models, and so
on).

Best,

Ernesto


On Thu, Nov 5, 2009 at 3:26 PM, Carlo Camerino <carlo.camerino@...>wrote:

> Hi,
>
> we created an implementation of IAuthorizationStrategy class.
> However, we need to access a spring managed object within that class?
> How do I get it to use a spring bean?
> @SpringBean annotation wouldn't work because it is not an instance of
> a Component.
>
> public class SampleAuthorizationStrategy implements IAuthorizationStrategy
> {
>
>   ( we want to inject a spring bean into this)
>    private HelloWorldService helloWorldService;
> }
>
>
>
> Thanks A Lot
> Carlo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>