Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 支柱和弹簧配置_Java_Spring Mvc_Struts_Spring Data - Fatal编程技术网

Java 支柱和弹簧配置

Java 支柱和弹簧配置,java,spring-mvc,struts,spring-data,Java,Spring Mvc,Struts,Spring Data,我有一个巨大的项目,其中一些部分是在某个春天搭建的 我在春季有一个Dao课程: @Component public class CouchDao { @Autowired(required = false) ICouchbaseTemplateInterface iCouchbaseTemplateInterface; public List<Couch> getUnExpiredForClient(int client) { Query query = new Query

我有一个巨大的项目,其中一些部分是在某个春天搭建的

我在春季有一个Dao课程:

@Component
public class CouchDao {
@Autowired(required = false)
ICouchbaseTemplateInterface iCouchbaseTemplateInterface;

public List<Couch> getUnExpiredForClient(int client) {
    Query query = new Query();
    CouchList=iCouchbaseTemplateInterface.findAllOrderBypostionAcrossVerticalDesc(query);
    List<Couch> CouchList=new ArrayList<Couch>();
    try {
        CouchList = iCouchbaseTemplateInterface.findAllOrderBypostionAcrossVerticalDesc(query);//CouchBase Query
    }
getUnExpiredForClient()中的Try部分引发了Null指针异常

我的action-servlet.xml如下所示:

<bean name="/**" class="**.APIAction">
    <property name="CouchDao" ref="CouchDao" />

</bean> 


同样的,请帮忙。

这里的问题是,使用struts,您正在“丢失”Spring上下文。Autowired注释为spring上下文初始化bean ICouchbaseTemplateInterface,但不为struts初始化

例如,由于您在struts操作xml文件中声明了bean CouchDao,struts框架可用于注入bean CouchDao,但它无法识别Autowired注释,因此ICouchbaseTemplateInterface未初始化,并引发NullPointerException。尝试将该bean也注入到xml中


对不起,我的英语不好:)

我是Struts新手。如果你能帮上忙,那就太好了。你能把你所有的action-servlet.xml和APIAction类都发布出来吗?action-servlet:这个类将保持不变。
<bean name="/**" class="**.APIAction">
    <property name="CouchDao" ref="CouchDao" />

</bean>