mybatis + oracle两个DAO错误

时间:2017-11-15 23:41:53

标签: java eclipse oracle mybatis

同时使用两个DAO是不可能的?

错误

private SqlSessionFactory factory = MyBatisconfig.getSqlSessionFactory(); 

getSqlSessionFactory(); < - 这是红线

错误

  

语法:MyBatisconfig类型的方法getSqlSessionFactory()引用缺少的类型SqlSessionFactory

以下是我正在使用的代码:

public class MyBatisconfig {
    private static SqlSessionFactory sqlSessionFactory;

    public static SqlSessionFactory getSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        String resource = "mybatis-config.xml";
        Reader reader; 
        try {
            reader = Resources.getResourceAsReader(resource);
            sqlSessionFactory =
                    new SqlSessionFactoryBuilder().build(reader);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sqlSessionFactory;
}

}

AdminDAO.class

private SqlSessionFactory factory = MyBatisconfig.getSqlSessionFactory();

UserDAO.class

private SqlSessionFactory factory = MyBatisconfig.getSqlSessionFactory();

的MyBatis-config.xml中

<configuration>
    <properties resource="db.properties" />

    <typeAliases>
        <typeAlias type="human.vo.User" alias="user" />
        <typeAlias type="human.vo.Admin" alias="admin" />

    </typeAliases>

    <environments default="development"> 
        <environment id="development"> 
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                <property name="driver" value="${driver}" />
                <property name="url" value="${url}" />
                <property name="username" value="${username}" />
                <property name="password" value="${password}" />
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="mappers/userMapper.xml" />
        <mapper resource="mappers/adminMapper.xml" />
    </mappers>

</configuration>

两个sqlSessionFactory&lt; ---不可能??

0 个答案:

没有答案