Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idea inspects batis mapper bean wrong

There's web project with Spring and MyBatis. I use IntelliJ IDEA for development. IDEA cannot correctly inspect MyBatis beans and produces annoying underscorings, though link to Data Access Object is present.

Inspection comment:

 Could not autowire. No beans of 'ApplicationMapper' type found.

My Spring and MyBatis configurations: Spring:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:spring/mybatis-config.xml"/>

</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.db.gbs.gbsapps.rds.backend.model.integration.mapping"/>
</bean>

mybatis-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <mappers>
        <mapper resource="mybatis/ApplicationMapper.xml"/>
    </mappers>
</configuration>

Is there a way to fix this small issue?

like image 425
Oleksandr Cherniaiev Avatar asked Aug 19 '14 08:08

Oleksandr Cherniaiev


2 Answers

@Repository
@Mapper 
public interface ApplicationMapper {

will do the trick

like image 168
Enrique Jiménez Flores Avatar answered Sep 19 '22 00:09

Enrique Jiménez Flores


Another way is to add @Component or @Repository to your mapper interface.

Such as:

@Repository
public interface ApplicationMapper {
    //...
}
like image 42
zhouji Avatar answered Sep 19 '22 00:09

zhouji