D.R.
D.R.

Reputation: 437

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.

Upvotes: 0

Views: 1732

Answers (1)

D.R.
D.R.

Reputation: 437

I had to add this line in

faces-config.xml

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

Upvotes: 2

Related Questions