开发者社区 问答 正文

Mac下Mybatis + Intellij 编译报错 400 请求报错 

Mac下Mybatis + Intellij 编译报错SqlSessionTemplate cannot be resolved to a type

Intellij导入Eclipse的web工程,编译报错

Caused by: java.lang.Error: Unresolved compilation problems: The import org.mybatis cannot be resolved SqlSessionTemplate cannot be resolved to a type SqlSessionTemplate cannot be resolved to a type SqlSessionTemplate cannot be resolved to a type SqlSessionTemplate cannot be resolved to a type SqlSessionTemplate cannot be resolved to a type

at com.sunlord.core.db.BaseMyBatisDao.<init>(BaseMyBatisDao.java:19)
at com.sunlord.core.db.GenericDao.<init>(GenericDao.java:18)
at com.sunlord.platform.dao.admin.WhatsNewDao.<init>(WhatsNewDao.java:11)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 62 more</pre> 

在Eclipse下编译没有问题,可以成功运行项目,但是Intellij下出错。 项目运行环境设置了jdk1.8.0_51,tomcat也是。 用gradle导入了MyBatis相关jar包 mybatis3.2.6 和 mybatis-spring1.2.2

展开
收起
kun坤 2020-05-29 17:45:28 734 分享 版权
1 条回答
写回答
取消 提交回答
  • 看看xml文件在编译的时候,是否正确被发布到运行目录下

    
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           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.xsd">
    
        <!-- 1. Data Source -->
        <import resource="classpath:config/datasource.xml"/>
    
        <!-- 2. SQL session factory -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="mapperLocations" value="classpath:mybatis-mapper/**/*.xml" /> <!-- Mapper xml -->
        </bean>
    
        <!-- 3. Instantiate Mapper -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.xtuer.dao.mybatis.mapper" />
        </bean>
    </beans>
    
    
    2020-05-29 17:45:34
    赞同 展开评论