Saturday, 15 August 2015

java - How to integrate Spring and JSF -



java - How to integrate Spring and JSF -

this question has reply here:

spring jsf integration: how inject spring component/service in jsf managed bean? 1 reply

how integrate spring , jsf? followed spring documentation (which sparse on subject) , googled more , found 2 working ways:

jsf managed bean spring @component / @named (but there doesn't seem work jsf scopes, spring scopes):

@component @scope("request") public class itemcontroller { @autowired private itemservice itemservice; }

i utilize @managedbean, jsf scopes work, cannot autowire spring bean using @autowired, bean must contain setter , i'm not sure if best practice:

@managedbean @requestscoped public class itemcontroller { @managedproperty("#{itemservice}") private itemservice itemservice; public void setitemservice(itemservice itemservice) { this.itemservice = itemservice; } }

something else?

i go way number 1 (and did in quite projects). makes no real sense mix jsf managed beans spring beans, unless have reason so. spring managed beans, have far more possibilities , can utilize total powerfulness of spring managed beans.

theoretically, there 3rd way: utilize cdi ui layer , spring in background. might alternative if don't want utilize total blown java ee environment still want benefit cdi , myfaces codi/deltaspike in ui layer. in case additionally need cdi setup , cdi spring bridge.

java spring jsf jsf-2

No comments:

Post a Comment