mybatis spring mvc应用程序,获取无效的绑定语句(未找到) [英] mybatis spring mvc application, getting Invalid bound statement (not found)
问题描述
这是我的第一个使用spring 3.2.4,mybatis-spring-1.2.1的mybatis spring mvc应用程序
this is my first mybatis spring mvc application using spring 3.2.4, mybatis-spring-1.2.1
当我尝试致电我的网络服务时,出现错误::
When i try to call my webservice i get the error::
org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is org.apache.ibatis.binding.BindingException: Invalid bound
statement (not found):
org.mydomain.formulary.drugmaster.dao.DrugMasterDao.getDrugsWithAlert
我肯定想念一些明显的东西. 感谢您的帮助
I must be missing something obvious. Thanks for any help
以下是我相关的文件: applicationContext.xml
Here are my associated files: applicationContext.xml
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="formularyDb" />
<property name="configLocation" value="file:/web/sites/drugformulary-spring/config/mybatis-config.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.mydomain.formulary.mappers" />
</bean>
<bean id="DrugMasterDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="org.mydomain.formulary.drugmaster.dao.DrugMasterDao" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
映射器文件->/classes/org/mydomain/formulary/mappers/drugmasterDao.xml
<mapper namespace="org.mydomain.formulary.drugmaster.dao.DrugMasterDao">
<select id="getDrugsWithAlert" parameterType="int" resultType="org.mydomain.formulary.drug_master.model.DrugMasters">
Select drug_id,drug_name,drug_alert_date,drug_alert_source, rownum
from (select drug_id,drug_name,to_char(drug_alert_datetime,'MM/DD/YYYY') as drug_alert_date ,drug_alert_source, rownum
from drug_master
where drug_status ='A' and length(drug_alert) > 0
order by drug_alert_datetime DESC )
where
<if test="_parameter != null">
rownum < #{count}
</if>
</select>
</mapper>
映射器文件->/classes/org/mydomain/formulary/drugmaster/dao/DrugMasterDao.java
public interface DrugMasterDao {
public List<DrugMasters> getDrugsWithAlert(int count);
}
控制器文件->/classes/org/mydomain/formulary/drugmaster/controller/DrugMasterController.java
@Controller
public class DrugMasterController {
@Autowired
DrugMasterService drugMasterService;
@RequestMapping(value = "/drugmaster/withalerts/count/{count}", method = RequestMethod.GET)
public String withAlerts(ModelMap model, @PathVariable int count) {
List<DrugMasters> drugs = drugMasterService.getDrugsWithAlert(count);
return null/*for now*/;
}
}
服务文件->/classes/org/mydomain/formulary/drugmaster/service/DrugMasterServiceImpl.java
@Service
public class DrugMasterServiceImpl implements DrugMasterService {
@Autowired
DrugMasterDao drugMasterDao;
public List<DrugMasters> getDrugsWithAlert(int count){
return drugMasterDao.getDrugsWithAlert(count);
}
}
mybatis-configfile->
<configuration>
<settings>
<setting name="cacheEnabled" value="false" />
<setting name="lazyLoadingEnabled" value="false" />
</settings>
</configuration>
推荐答案
在查找错误时,我用谷歌搜索了此答案.它实际上与OP的问题无关,但例外是相同的,并且该问题在google中非常明显.
I googled this answer when looking for my error. It's actually unrelated to OP's problem, but the exception is the same and this question's very visible in google.
就我而言,我忘记更改映射器名称空间
In my case I forgot to change the mapper namespace
<mapper namespace="pl.my.package.MyNewMapper">
哪个导致了同样的问题.
Which resulted in the same problem.
这篇关于mybatis spring mvc应用程序,获取无效的绑定语句(未找到)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!