Jsf 2.0 spring 3 query area not working

I am trying to use spring to provide managed beans jsf. I assume that @ManagedBean will be captured by the JSF container to bind EL in JSF with a managed bean, even when I use spring by setting the use of spring in faces-config.xml.

Spring should provide beans, but now , which manages the beans scope?

I tried the following annotation on beans so that it becomes a request scope, but they do not work.

@ManagedBean(name="helloBean") //meant for JSF
@RequestScoped //meant for JSF
@Scope(value="request") //meant for spring
@Controller //meant for spring
public class HelloBean implements Serializable {

In fact, I used to use simple JSFs, while @ManagedBean and @RequestScoped worked well. Now that I tried to integrate using spring, the scope is not working.

I even tried setting the bean scope to spring configuration, but they work as expected in the spring context (singleton and prototype), but not in the context of the web request.

I tried to avoid using the above @Scope and @Controller annotation, hoping that JSF would manage the scope, but not look.

Below are the file fragments for spring config and MyHelloBean, which are likely to help you communicate better.

<bean id="helloBean" class="com.mkyong.common.HelloBean" init-method="init" />

<bean id="myHelloBean" class="com.mkyong.common.MyHelloBean" init-method="init" >
        <property name="helloBean" ref="helloBean"></property>
</bean>

@ManagedBean
@RequestScoped
@Scope(value="request")
@Controller
public class MyHelloBean implements Serializable {

    private static final long serialVersionUID = 1L;
    //@ManagedProperty(value = "#{helloBean}")
    private HelloBean helloBean;

see above MyHelloBean I use spring DI to install helloBean, which installs with spring in order. I commented on @ManagedBean, which I think I can leave it there, as it will be ignored by spring by any means, and the JSF is not going to handle it. I suppose, but to be safe, I commented on this so that the JSF doesn't process it.

, faces-config spring.

<el-resolver> 
org.springframework.web.jsf.el.SpringBeanFacesELResolver 
</el-resolver> 

,

Miten.

+5
2

, , XML Spring Spring . , , :

<context:component-scan base-package="com.yourcom.package" />

Spring . , XML, :

<bean id="helloBean" class="com.mkyong.common.HelloBean" init-method="init" scope="request" />

scope Spring bean singleton.

+2

, JSF Spring beans, . .

, , Spring beans, . Spring JSF .

  • , Spring JSF :

@RequestScoped ​​ @Scope ( "" ) Spring .. .

  • , Spring JSF:

@ViewScoped Spring , ( ) Spring , ( ).

Bean

JSF2 @ManagedProperty , Spring @Autowired . ?

  • Spring beans @ManagedProperty:

Spring, , , jsf: @Component (value = "valueMatches" ), @ManagedProperty (value = "valueMatches" ).

  • Spring beans @Autowired:

Spring, , , bean, : @Component, @Autowired.

Spring beans, Scopes Injection.

JSF beans @Scope (value = "wishScope" ), @Controller (value = "beanName" ) @Qualifier (value = "beanName" ) . , JSF in faces-config.xml beanName, @Controller.

Spring @Service.

Spring JSF beans @Autowired .

, ViewScope FlashScope beans. , JSF2 .

, .

+5

All Articles