mkoryak
mkoryak

Reputation: 57938

How to @autowire into jsf managed beans

In order to use the @Autowire annotation, the object where you use the annotation must come from the spring context.

JSF managed beans are created by JSF's IOC not Springs, therefor i cannot use @Autowire inside of them must must use faces-config.xml and managed properties.

I already setup an EL resolver that lets be have spring beans as managed properties, i want to take it one step further and get rid of the need to go into the faces-config.xml every time i need to autowire something. Is this possible?

Upvotes: 6

Views: 17918

Answers (2)

E A
E A

Reputation: 1244

You can use @ManagedProperty(#{'someBean'}) for autowire other beans in jsf bean

Upvotes: 4

Bozho
Bozho

Reputation: 597106

Just annotate your managed beans with @Controller (or @Component), and @Scope("request") (or session) and add <context:component-scan> (if you haven't), and managed beans will automatically be detected as spring beans. And since you are already using the ELResolver, that should be it - you should be able to use @Autowired (or better - @Inject, if using spring 3.0).

Upvotes: 12

Related Questions