|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Apr 2005
Messaggi: 31
|
[JAVA] problema con JNDI
ciao a tutti, ho un problema che mi sta facendo diventar matto, praticamente ho settato 2 jndi 1 per accedere ad un db e l'altra per accedere ad un file di properties in modo da poter gestire alcuni parametri esternamente all'applicazione, la jndi jdbc viene letta correttamente, invece la jndi del file di properties mi va in errore.
innanzi tutto vi spiego la mia configurazione, ho un server tomcat 5.5, struts 1.3, winxp, eclipse helios sp1. poi nel web.xml ho queste righe di codice Codice:
<resource-ref id="ResourceRef1">
<res-ref-name>jdbc/DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref id="ResourceRef3">
<description>file Properties</description>
<res-ref-name>url/fileprop</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Codice:
<Resource name="jdbc/DB" auth="Container" type="javax.sql.DataSource" username="user" password="pass" driverClassName="com.ibm.db2.jcc.DB2Driver" url="jdbc:db2://192.xxx.xxx.xxx:50000/DBName"/> <Resource name="url/fileprop" auth="Container" type="java.net.URL" url="C:\deploy\file.properties"/> Codice:
Context initial = new InitialContext();
Context env = (Context) initial.lookup("java:comp/env");
javax.sql.DataSource data = (javax.sql.DataSource)PortableRemoteObject.narrow(
env.lookup("jdbc/DB"),javax.sql.DataSource.class);
URL prop = (URL) PortableRemoteObject.narrow(
env.lookup("url/fileprop"), URL.class);
quando chiamo il file di properties mi ritorna questo errore Codice:
javax.naming.NamingException: Cannot create resource instance at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143) at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304) at org.apache.naming.NamingContext.lookup(NamingContext.java:793) at org.apache.naming.NamingContext.lookup(NamingContext.java:140) at org.apache.naming.NamingContext.lookup(NamingContext.java:781) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) Qualcuno sa aiutarmi?? |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2002
Città: Palermo
Messaggi: 4913
|
Probabilmente il file non lo devi considerare come una "Resource" come la url del db,
http://tomcat.apache.org/tomcat-5.5-...g/context.html Se per esempio provi in questo modo ?
__________________
Sun Certified Java Programmer - Sun Certified Web Component Developer - Sun Certified Business Component Developer |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Apr 2005
Messaggi: 31
|
grazie della risposta, ho risolto in questo modo.
nel context.xml del server ho dichiarato un enviroment Codice:
<Environment name="fileprop" type="java.lang.String"
value="C:\deploy\file.properties"/>
e poi mi faccio restituire il valore in questo modo Codice:
String fileStr = (String) env.lookup("fileprop");
nel web.xml non ho aggiunto nulla. |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 17:34.



















