简体   繁体   English

无法在托管bean中注入接口

[英]can not inject interface in a managed bean

I am writing a web application using Spring and PrimeFaces. 我正在使用Spring和PrimeFaces编写Web应用程序。 I am trying to inject interface in my managedBean, but when I try to use it, it is null and I get an Exception. 我试图在我的managedBean中注入接口,但是当我尝试使用它时,它是null并且我得到一个异常。

Here is the datasource-config.xml : 这是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类是这样的:

@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 . myTestService保持为null

I had to add this line in 我不得不添加这一行

faces-config.xml faces-config.xml中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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