Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

mybatis spring mvc application, getting Invalid bound statement (not found)

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

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>

mapper file --> /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 &lt; #{count}
    </if>
</select>
</mapper>

mapper file --> /classes/org/mydomain/formulary/drugmaster/dao/DrugMasterDao.java

public interface DrugMasterDao {
    public List<DrugMasters> getDrugsWithAlert(int count);
}

controller file --> /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*/;

}
}    

service file --> /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>

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...