Women in Technology

Hear us Roar

  Hibernate for Java SE
Subject:   still use Spring & JNDI
Date:   2005-11-17 14:00:29
From:   brondsem
I do something similar, but continue to use Spring (it wires nearly everything together, so I must, and it's good to use) and JNDI to get a handle for my datasource. No changes to my code. IIRC, all I had to do was change my spring applicationContext.xml to use "classpath:hibernate.cfg.xml" as the value of "configLocation" (on my org.springframework.orm.hibernate3.LocalSessionFactoryBean), put the same hibernate.cfg.xml file on my classpath when running my j2se code, and provide the JNDI environment and datasource with simple-jndi (from http://www.osjava.org/simple-jndi/) instead of Tomcat. I'd be happy to provide more details if anyone wants; configuring simple-jndi took me a little while.
Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • still use Spring & JNDI
    2005-11-17 16:44:54  Jason-Lee [View]

    I think this would be a good addition, so post if you please. :)

    • still use Spring & JNDI
      2005-11-18 07:09:31  brondsem [View]

      To get spring working, follow my comments above, and also the j2se app needs something like this to load the spring application context(s):

      public class MyDataLoader {
      protected AbstractApplicationContext ctx;
      public static void main(String[] args) {
      new MyDataLoader(args).load();
      public MyDataLoader(String[] appContextFiles) {
      ctx = new FileSystemXmlApplicationContext(appContextFiles);

      To provide a JNDI environment with simple-jndi all you have to do is put the simple-jndi jar file in the classpath and a jndi configuration dir (e.g. ${user.home}/test-jndi) on the classpath. In ${user.home}/test-jndi create jndi.properties:

      org.osjava.sj.root=file:///c:/Documents and Settings/myUserID/test-jndi/jndi-entries

      And create ${user.home}/test-jndi/jndi-entries/java!comp/env/jdbc/myDataSourceName.properties


      Don't forget to put other container-provided jars that you may need (e.g. your jdbc driver) on the j2se app's classpath.