错误:domain.SpeakerRecog.test上的java.lang.NullPointerException
SpeakerMapper为null, speakermapper.insertUserAndEnrollmentId(userid, enrollmentid)出错speakermapper.insertUserAndEnrollmentId(userid, enrollmentid)它抛出Java空指针异常。 数据源是在控制台中创建的。 我尝试添加诸如@Configuration , implements类的注释,但仍无法正常工作。 我试图将数据插入localhost中数据库的表中。 它与线程“为什么我的Spring @Autowired字段为null为何”不同。 因为我没有创建新的构造函数,但是我遵循了那里给出的建议,但是它仍然无法正常工作
WebService Java文件:
package domain;
import javax.jws.WebMethod;
import javax.jws.WebService;
import mapper.Speakermapper;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import org.springframework.beans.factory.annotation.Autowired;
@WebService(serviceName = "SpeakerRecognitionWS")
public class SpeakerRecog extends SpringBeanAutowiringSupport{
@Autowired
private Speakermapper speakermapper;
@WebMethod
public String test(){
String userid = "111";
String enrollmentid = "111";
try{
speakermapper.insertUserAndEnrollmentId(userid, enrollmentid);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
这是Speakermapper.java文件:
package mapper;
import org.apache.ibatis.annotations.Param;
public interface Speakermapper {
public void insertUserAndEnrollmentId(@Param("userid") String userid,
@Param("enrollmentid") String enrollmentid);
}
**这里是Speakermapper.xml:
Insert into SpeakerIds
(userid, enrollmentid)
Values (#{userid}, #{enrollmentid})
**这里是applicationContext.xml:此xml是否存在错误。 我不知道。
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation= "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">