Development environment configuration

xiaoxiao2021-03-06  69

The environment in development is as follows: Write a start-up class load and bind hibernate's sessionFactory to WebLogic code as follows: Public class hibernatestartup imports t3startupdef {

public static String CONFIG_FILE_PATH = "/hibernate.cfg.xml"; public void setServices (T3ServicesDef services) {} public static final String SESSION_FACTORY_JNDI = "hibernate"; public static final String URL = "t3: // localhost: 7001"; public String Startup (String Name, Hashtable Args "Throws Exception {Try {

doBind (); return "Hibernate Startup completed successfully";} catch (Exception e) {} return "Hibernate Startup completed successfully";} private static void doBind () throws Exception {Properties environment = null; InitialContext context = null;

try {environment = new Properties (); environment.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); environment.put (Context.PROVIDER_URL, URL); context = new InitialContext (environment);

Configuration configuration = (new Configuration ()) configure (CONFIG_FILE_PATH);. SessionFactory factory = configuration.buildSessionFactory (); if (factory == null) throw new Exception ( "SessionFactory can not be built ?!");

Try {IF ("Hibernate")! = null) {Context.rebind ("Hibernate", Fact.);} else {context.bind ("hibernate", factory);}} catch (namingexception nameex) { nameEx.printStackTrace (); context.bind ( "hibernate", factory);}} catch (NamingException nameExp) {throw new Exception ( "NamingException:" nameExp.getMessage ());} catch (Exception excp) {throw excp }}

Static Private InitialContext GetInitialContext () THROWS Exception {String Url = "T3: // localhost: 7001";

Properties properties = null; try {properties = new Properties (); properties.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put (Context.PROVIDER_URL, url); return new InitialContext (properties);} Catch (Exception E) {Logger.fatal ("Unable to Connect To Weblogic Server AT" URL); Logger.fatal ("Please Make Sure That The Server Is Running."); throw E;}}} then compiles in JBuilder2005 Calsspath under configserver Add this path of this class, I am C: / Work / OversTock / Classes and then add Hibernate's JAR file to the JAR file, it can be developed. When deploying, just add these paths to the StartWebLogic.cmd of Domain, but you have to put the classes in the C: / Work / OversTock / Classes and add it, and if weblogic can be found. Reference article: http://www.hibernate.org/120.html

转载请注明原文地址:https://www.9cbs.com/read-90599.html

New Post(0)