ERROR: java.lang.NullPointerException at domain.SpeakerRecog.test
speakermapper is null, error is on speakermapper.insertUserAndEnrollmentId(userid, enrollmentid)
it throws Java null pointer exception. Datasource was created in console. I tried adding annotations like @Configuration
, implements
, it still wont work. I am trying to insert data into table of a database in localhost. Its different from the thread "Why is my Spring @Autowired field null?" since i did not create a new constructor, but i followed the suggestion given there but it still wont work
WebService java file:
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();
}
}
}
Here is Speakermapper.java file:
package mapper;
import org.apache.ibatis.annotations.Param;
public interface Speakermapper {
public void insertUserAndEnrollmentId(@Param("userid") String userid,
@Param("enrollmentid") String enrollmentid);
}
**Here is Speakermapper.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace = "mapper.Speakermapper">
<insert id = "insertUserAndEnrollmentId" >
Insert into SpeakerIds
(userid, enrollmentid)
Values (#{userid}, #{enrollmentid})
</insert>
</mapper>
**Here is applicationContext.xml: Is there error on this xml. I cant figure it out.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<context:component-scan base-package="domain"/>
<context:component-scan base-package="mapper"/>
<bean id="SpeakerRecog" class="domain.SpeakerRecog" />
<bean id="smapper" class="mapper.speakermapper" />
<bean id="dataSourceSpeaker" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="Speaker"/>
</bean>
<bean id="sqlSessionFactorySpeaker" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceSpeaker"/>
<property name="typeAliasesPackage" value="domain"/>
<property name="configLocation" value="/WEB-INF/mybatis-config.xml"/>
</bean>
<bean id="mapperSpeaker" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactorySpeaker" />
</bean>
</beans>