0

我正在使用 Spring 和 PrimeFaces 编写一个 Web 应用程序。我试图在我的 managedBean 中注入接口,但是当我尝试使用它时,它为空并且我得到一个异常。

这是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>

我的 managedBean 类是这样的:

@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仍然null

4

1 回答 1

2

我不得不添加这一行

面孔-config.xml

<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
于 2013-04-24T14:25:57.113 回答