| Article: |
Hibernate for Java SE | |
| Subject: | still use Spring & JNDI | |
| Date: | 2005-11-17 16:44:54 | |
| From: | Jason-Lee | |
|
Response to: still use Spring & JNDI
|
||
|
I think this would be a good addition, so post if you please. :)
|
||
Showing messages 1 through 1 of 1.
-
still use Spring & JNDI
2005-11-18 07:09:31 brondsem [View]



public class MyDataLoader {
protected AbstractApplicationContext ctx;
public static void main(String[] args) {
new MyDataLoader(args).load();
}
public MyDataLoader(String[] appContextFiles) {
super();
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:
java.naming.factory.initial=org.osjava.sj.SimpleContextFactory
org.osjava.sj.root=file:///c:/Documents and Settings/myUserID/test-jndi/jndi-entries
org.osjava.sj.delimiter=/
org.osjava.sj.colon.replace=!
And create ${user.home}/test-jndi/jndi-entries/java!comp/env/jdbc/myDataSourceName.properties
type=javax.sql.DataSource
driver=net.sourceforge.jtds.jdbc.Driver
url=jdbc:jtds:sqlserver://host:1433/databaseName;SelectMethod=cursor
user=myUsername
password=myPassword
Don't forget to put other container-provided jars that you may need (e.g. your jdbc driver) on the j2se app's classpath.