mybatis reads the configuration file to obtain SqlSessionFactory instance.

Singleton obtain an instance, the subsequent integration spring, create an instance of a cross-spring to complete.

the SessionFactory class {public
// factory object
Private static Factory a SqlSessionFactory = null;
// static block
static {
the try {
// load profile
the InputStream Stream = Resources.getResourceAsStream ( "the SqlMapConfig.xml");
Factory the SqlSessionFactoryBuilder new new = (). Build (Stream);
} the catch (Exception E) {
e.printStackTrace ();
}
}
// constructor privatization
Private the SessionFactory () {}
// get factory instance
public static getFactory a SqlSessionFactory () {
return factory;
}
// examples from the session
public static the SqlSession the getSession () {
return factory.openSession ();
}
}

Guess you like

Origin www.cnblogs.com/yunianzeng/p/11825295.html