同时使用两个DAO是不可能的?
以下是我使用的代码:
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中
<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>
使用getSqlSessionFactory会抛出错误。