Put all the bags used by Hibernate into the lib application's lib, then define hibernate.cfg.xml, which is the configuration information of the plugin, as follows
XML Version = "1.0" Encoding = "UTF-8"?>
session-factory> hibernate-configuration> The information is clear, it is to configure the database and other information, we use JNDI to find sessionFactory, below is the plug-in, HibernatePlugin.java
import org.apache.struts.action.PlugIn; import org.apache.struts.action.ActionServlet; import org.apache.struts.config.ModuleConfig; import javax.servlet.ServletException; import javax.servlet.ServletContext; import net. sf.hibernate.SessionFactory; import net.sf.hibernate.cfg.Configuration; public class HibernatePlugIn implements PlugIn {public void destroy () {} public void init (ActionServlet servlet, ModuleConfig config) throws ServletException {try {ServletContext context = servlet. getServletContext ();.. SessionFactory sf = new Configuration () configure () buildSessionFactory (); context.setAttribute ( "net.sf.hibernate.SessionFactory", sf);} catch (Exception ex) {ex.printStackTrace (); }}} The corresponding, to configure the plugin information in struts-config.xml, approximately the path
You can use java.naming.context, java.naming.initiacontext, java.naming.initiacontext.
Context ct = new initialContext (); sessions = (sessionFactory) ct.lookup ("Hibernate / session_factory); session = sessions.opensesis ();
Of course, there are other two kinds of integration, I think this method is more flexible, it is more likely to master