遇到异常,下面是日志:
org.springframework.beans.factory.BeanCreationException:创建名称为'speaker'的bean时出错:自动连接依赖项的注入失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:无法自动装配方法:public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate);嵌套异常是java.lang.NoSuchMethodError:org.springframework.core.MethodParameter.getNestedParameterType()Ljava / lang / Class
java Web服务:
@WebService
public class voiceRecognition extends SpringBeanAutowiringSupport {
@Autowired
private Speaker speaker;
@WebMethod
public void test() {
String userid = "111";
String enrollmentid = "111";
try{
String test1 = speaker.getEnrollmentId(userid);
System.out.println(test1);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Speaker.java:
package ph.com.aub.mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
@Service
public interface Speaker {
public String getEnrollmentId(@Param("userid") String userid);
}
Speaker.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 = "ph.com.aub.mapper.Speaker">
<select id = "getEnrollmentId" resultType = "string" parameterType = "string">
Select enrollmentid from speakerids where userid = #{userid}
</select>
</mapper>
web.xml:
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>voiceRecognitionPort</servlet-name>
<!--<servlet-class>ph.com.aub.domain.voiceRecognition</servlet-class>-->
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>voiceRecognitionPort</servlet-name>
<url-pattern>/voiceRecognitionPort</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="ph.com.aub.domain.voiceRecognition"/>
<context:component-scan base-package="ph.com.aub.mapper"/>
<context:annotation-config/>
<bean id="dataSourceSpeaker" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="Speakerdata"/>
</bean>
<bean id="sqlSessionFactorySpeaker" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceSpeaker"/>
<property name="typeAliasesPackage" value="ph.com.aub.domain"/>
<property name="configLocation" value="/WEB-INF/mybatis-config.xml"/>
</bean>
<bean id="mapperSpeaker" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="ph.com.aub.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactorySpeaker" />
</bean>
</beans>
答案 0 :(得分:0)
我相信您在basePackage
中的MapperScannerConfigurer
配置不正确。它应该是包含mapper类而不是mapper类本身的包。因此,尝试将basePackage
更改为:
<bean id="mapperSpeaker" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="ph.com.aub.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactorySpeaker" />
</bean>