tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mangan <man...@aptrut.com>
Subject Re: Configure datasource to work with JBoss style lookups?
Date Thu, 02 Oct 2008 12:11:38 GMT

Well, you are right about the classpath error. I've fixed that now. 

The solution you propose is more or less impossible for me to implement
because the datasource lookup I described earlier is found in a layer
underneath the class I'm running my unit tests on. I don't have the
possibility to change the lookup. So is it possible to do the same thing
directly in the openejb.xml or by passing parameters to the JVM directly?

Thanks!

// Magnus



Andreas Karalus wrote:
> 
> Hi,
> 
> it looks like for me like you are having some jndi and classpath 
> problems, take a look if you still have some jboss specific
> jndi.properties.
> 
> java.naming.factory.url.pkgs org.jboss.naming:org.jnp.interfaces
> 
> anyway I found a simple way to bind a datasource in jboss specific
> style(we are using jboss in production and  openejb in junit tests). You
> can try something  like this
> 
> p.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>         p.put("java:/movieDatabase", "new://Resource?type=DataSource");
>         p.put("java:/movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
>         p.put("java:/movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
> 
>         Context context = new InitialContext(p);
> 
> 
> -> context.lookup("java:/movieDatabase") should then work ... 
> 
> regards,
> andreas
> 
> 
> Mangan wrote:
>> 
>> Hi!
>> 
>> I recentally started using OpenEJB for doing unit testing with JUnit.
>> I've got it to work for everything I've tried so far but now I've run
>> into some problems: 
>> 
>> When trying to unit test a method, that in a lower layer uses a database
>> connection, I get an error. 
>> 
>> java.lang.NoClassDefFoundError: org/jnp/server/NamingServer
>> 	at
>> org.jboss.naming.java.javaURLContextFactory.<clinit>(javaURLContextFactory.java:52)
>> 	at java.lang.Class.forName0(Native Method)
>> 	at java.lang.Class.forName(Class.java:242)
>> 	at
>> com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:50)
>> 	at
>> com.sun.naming.internal.ResourceManager.getFactory(ResourceManager.java:371)
>> 	...
>> Code for lookup:
>> try{
>> 	InitialContext ctx = new InitialContext();
>> 	DataSource ds = (DataSource) ctx.lookup( "java:/MyDataSource");
>> 	return ds.getConnection();
>> }
>> // If we arn't in a JBoss context, 
>> catch ( NamingException ne){
>> 	throw new RuntimeException("NamingException while getting a JDBC
>> connection");
>> }
>> 
>> This does not suprise me because I've read some posts about problems when
>> using a JBoss-style lookup on datasources ("java:/DataSourceName"). In my
>> inital tests I've got the datasource configured in the open-ejb.xml and
>> the connection to work via annotations. So I know my datasource works. I
>> would gladly change my datasource lookups in the future when using JBoss
>> (if it's possible) but the projekt I'm working on now is huge so that's
>> not really an option.
>> 
>> Is there some way to setup the datasource to be able to use JBoss-style
>> lookups?
>> 
>> Or, am I mistaken in my assumption that this have anything to do with the
>> datasource lookup?
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Configure-datasource-to-work-with-JBoss-style-lookups--tp19720947p19778034.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Mime
View raw message