我正在使用 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
。