简体   繁体   中英

can not inject interface in a managed bean

I am writing a web application using Spring and PrimeFaces. I am trying to inject interface in my managedBean, but when I try to use it, it is null and I get an Exception.

Here is the datasource-config.xml :

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


<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:comp/env/jdbc/testDS</value>
    </property>
</bean>

<bean id="myTestService" class="com.myTest.service.MyTestService">
    <property name="dataSource" ref="dataSource"/>
</bean>

and my managedBean class is like this :

@ManagedBean(name="myList")
@SessionScoped

public class MyListBean {

private LazyDataModel<Merchant> lazyModel;
@Autowired  
@ManagedProperty(value = "#{myTestService}")
private MyTestServiceInterface myTestService;

public MyListBean (){
    int a = myTestService.getRecordsCount() ;

}

public LazyDataModel<Merchant> getLazyModel() {
    return lazyModel;
}


public void setLazyModel(LazyDataModel<Merchant> lazyModel) {
    this.lazyModel= lazyModel;
}

public MyTestServiceInterface getMyTestService() {
    return myTestService;
}

public void MyTestServiceInterface (MyTestServiceInterface myTestService) {
    this.myTestService= myTestService;
}

}

myTestService remains null .

I had to add this line in

faces-config.xml

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM