2012-03-18 3 views
0

JSF ManagedBean에 스프링 빈을 삽입하려고한다. 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 빈에 대한 주석을 사용하고 싶습니다. 그래서 @ManagedBean annotated bean에 TestService을 삽입하는 방법은 무엇입니까? 당신은 당신이 @ManagedProperty에 값을 대체 할 수있는 XML 파일에서 빈을 정의함에 주석

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

를 사용하는 것처럼

답변

1

당신은 서비스 Implementaion 정의 @ManagedProperty

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

를 통해 그것을 주입 사용할 수 있습니다 그 bean id에 의한 주입

희망이 도움이 !!!!