2012-03-18 68 views
0

我想在JSF ManagedBean中注入spring bean。現在我用: 的applicationContext.xml:如何在Spring + JSF應用程序中使用JSF註釋

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <bean id="service" class="com.evgeny.domain.TestService"></bean> 

</beans> 

臉-config.xml中:

<faces-config 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" 
    version="2.0"> 

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

    <managed-bean> 
     <managed-bean-name>facesBean</managed-bean-name> 
     <managed-bean-class>com.evgeny.jsf.FacesBean</managed-bean-class> 
     <managed-bean-scope>session</managed-bean-scope> 
     <managed-property> 
      <property-name>service</property-name> 
      <value>#{service}</value> 
     </managed-property> 
    </managed-bean> 

</faces-config> 

...和它的作品。但是我想爲JSF bean使用註釋。那麼如何在@ManagedBean註釋bean中注入TestService

回答

1

你,如果使用如您定義的XML文件豆你可以在@ManagedProperty替代值註釋

@Service(value = "testService") 
public class TestServiceImpl implements TestService 

可以使用@ManagedProperty

通過

@ManagedProperty(value="#{testService}") 
private TestService testService; 

注入它定義服務Implementaion由該豆編號注射

希望這有助於!