well the openejb lookup clearly works even with spring (see https://github.com/rmannibucau/lookup-from-spring-in-tomee/blob/master/src/main/webapp/WEB-INF/applicationContext.xml#L13) so there should be something linked to your setup. Listing JNDI is a more complicated task than doing a list() on a context cause several contexts are aggregated.
Romain Manni-Bucau @rmannibucau <https://twitter.com/rmannibucau> | Blog <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> | LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber <http://www.tomitribe.com> | JavaEE Factory <https://javaeefactory-rmannibucau.rhcloud.com> 2016-08-03 18:47 GMT+02:00 KARR, DAVID <[email protected]>: > > -----Original Message----- > > From: Romain Manni-Bucau [mailto:[email protected]] > > Sent: Tuesday, August 02, 2016 11:53 PM > > To: [email protected] > > Subject: Re: Define datasource, reference JDBC driver, and see init in > > console > > > > Hello > > > > Before digging deeper in your problem a small note on this one: since > > you encounter some issue with the doc I would love you to try to > > enrich/rewrite some part of it to make it smoother for next newcomer. > > Would it be possible? > > > > Next about your issue: > > > > - using jdbc/sus2 you can use @Resource(name = "jdbc/sus2") DataSource > > ds; or do a lookup on openejb:Resource/jdbc/sus2 or > > java:openejb/Resource/ > > jdbc/sus2 > > None of these lookup patterns worked. Is there some way I can get a list > of what was finally registered? I tried executing some code like this: > ---------- > List<NameClassPair> nameClassPairList = new > ArrayList<>(); > InitialContext context = new InitialContext(); > NamingEnumeration<NameClassPair> contextNames = > context.list("java:comp/env"); > while (contextNames.hasMore()) { > nameClassPairList.add(contextNames.next()); } > return nameClassPairList; > --------------- > > With various expressions in the "list()" parameter, but I haven't found > any trace of "sus2" anywhere. > > > 2016-08-03 1:21 GMT+02:00 KARR, DAVID <[email protected]>: > > > > > I may be making some progress. Working from > > > http://tomee.apache.org/tomee-and-eclipse.html , it appears that the > > > "tomeee.xml" file that I edited in the Tomee distro is not used in > > > Eclipse. I used the "Import" feature as described to copy the file > > into > > > the server defined in Eclipse. At that point, I got an error like > > this: > > > --------------------- > > > org.apache.openejb.OpenEJBException: > > > Unable to read OpenEJB configuration file at > > > > > <workspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\tom > > ee.xml: > > > Unsupported Attribute(s): maxActive, maxIdle, maxWait, > > > driverClassName, url, username, password. > > > Supported Attributes are: type, jar, provider, id, class-name, > > > constructor, factory-name, classpath, jndi, aliases, > > > properties-provider, property-provider, depends-on. If the setting is > > > a configuration property it must be placed inside the element body. > > > --------------------- > > > > > > Really strange. > > > > > > I then modified the imported "tomee.xml" file, resulting in the > > > following approximate Resource definition: > > > -------------------- > > > <Resource id="jdbc/sus2" type="DataSource" > > > classpath="mvn:oracle:ojdbc6:11.2.0.3" > > > class-name="oracle.jdbc.driver.OracleDriver"> > > > maxActive = 5 > > > maxIdle = 2 > > > maxWait = 10000 > > > url = jdbc:oracle:thin:@<host>:1521:<sid> > > > username = <userid> > > > password = <password> > > > </Resource> > > > -------------- > > > > > > When I start up the server, I see the following in the console: > > > ------------------ > > > Aug 02, 2016 4:13:03 PM org.apache.openejb.config.ConfigurationFactory > > > configureService > > > INFO: Configuring Service(id=jdbc/sus2, type=Resource, > > > provider-id=jdbc/sus2) > > > Aug 02, 2016 4:13:03 PM org.apache.openejb.util.OptionsLog info > > > INFO: Using 'openejb.deployments.classpath=false' > > > Aug 02, 2016 4:13:03 PM org.apache.openejb.assembler.classic.Assembler > > > createRecipe > > > INFO: Creating TransactionManager(id=Default Transaction Manager) Aug > > > 02, 2016 4:13:03 PM org.apache.openejb.assembler.classic.Assembler > > > createRecipe > > > INFO: Creating SecurityService(id=Tomcat Security Service) Aug 02, > > > 2016 4:13:03 PM org.apache.openejb.assembler.classic.Assembler > > > createRecipe > > > INFO: Creating Resource(id=jdbc/sus2) > > > Aug 02, 2016 4:13:03 PM org.apache.openejb.assembler.classic.Assembler > > > unusedProperty > > > WARNING: unusedProperty maxActive - jdbc/sus2 Aug 02, 2016 4:13:03 PM > > > org.apache.openejb.assembler.classic.Assembler > > > unusedProperty > > > WARNING: unusedProperty maxIdle - jdbc/sus2 Aug 02, 2016 4:13:03 PM > > > org.apache.openejb.assembler.classic.Assembler > > > unusedProperty > > > WARNING: unusedProperty maxWait - jdbc/sus2 Aug 02, 2016 4:13:03 PM > > > org.apache.openejb.assembler.classic.Assembler > > > unusedProperty > > > WARNING: unusedProperty url - jdbc/sus2 Aug 02, 2016 4:13:03 PM > > > org.apache.openejb.assembler.classic.Assembler > > > unusedProperty > > > WARNING: unusedProperty username - jdbc/sus2 Aug 02, 2016 4:13:03 PM > > > org.apache.openejb.assembler.classic.Assembler > > > unusedProperty > > > WARNING: unusedProperty password - jdbc/sus2 > > > ----------------- > > > > > > I don't understand what "unusedProperty" means (weird that it's just > > > one word). > > > > > > When I later try to reference that resource, I get the following: > > > -------------------- > > > javax.naming.NameNotFoundException: Name [jdbc/sus2] is not bound in > > > this Context. Unable to find [jdbc]. > > > -------------------- > > > > > > It's not clear to me whether that Resource definition put anything > > > into the JNDI context, or whether I'm just using the wrong JNDI path > > > to reference it. > > > > > > -----Original Message----- > > > From: Daniel Cunha [mailto:[email protected]] > > > Sent: Tuesday, August 02, 2016 2:10 PM > > > To: TomEE Users <[email protected]> > > > Subject: Re: Define datasource, reference JDBC driver, and see init in > > > console > > > > > > Hi David, > > > > > > yea, resources on TomEE is a mix (XML/Properties) Your definition > > > should following the pattern: > > > <Resource id="jdbc/sus2" type="DataSource"> > > > maxActive = 5 > > > maxIdle = 2 > > > maxWait = 10000 > > > driverClassName = oracle.jdbc.driver.OracleDriver > > > url = jdbc:oracle:thin:@<host>:1521:<sid> > > > username = <user> > > > password = <password> > > > </Resource> > > > > > > References you can see here: > > > http://tomee.apache.org/datasource-config.html > > > About maven, should be enough have the configuration in your > > settings.xml. > > > :) > > > > > > On Tue, Aug 2, 2016 at 5:52 PM, KARR, DAVID <[email protected]> wrote: > > > > > > > (I posted this first to tomcat-user, but I realized technically it > > > > should go to tomee-user. I apologize if this is a duplicate for > > you. > > > > In any case, this note has a little more info than the first note.) > > > > > > > > I'm attempting to use Tomcat(tomee) to run a REST service that will > > > > return some data from some SQL queries (Oracle). I've installed > > > > Tomee 7.0.1, which uses Tomcat 8.5.3. > > > > > > > > The JDBC driver is available from a private enterprise maven repo. > > > > I'd prefer to get it from there, as opposed to storing it locally. > > > > I noticed at http://tomee.apache.org/configuring-datasources.html , > > > > there is the possible notation of "mvn:g:a:v" for the "classpath" > > > > attribute. However, I don't see any way to configure the Maven > > > repositories this will reference. > > > > How do I tell it to look in a particular repo for this? Would it > > > > just implicitly use my $HOME/.m2/settings.xml file? > > > > > > > > My Resource definition in "conf/tomee.xml" looks something like > > this: > > > > ----------------------- > > > > <Resource id="jdbc/sus2" type="DataSource" > > > > maxActive="5" maxIdle="2" maxWait="10000" > > > > driverClassName="oracle.jdbc.driver.OracleDriver" > > > > url="jdbc:oracle:thin:@<host>:1521:<sid>" > > > > username="<user>" password="<password>"/> > > > > ---------------- > > > > > > > > Does this look correct? I find the Tomcat docs confusing, with > > > > respect to the required syntax for this. It's not clear whether a > > > > pure XML syntax is required, or a mixed XML/property syntax. > > > > > > > > If I start the instance, should I see any default output that will > > > > show Tomcat connecting to this datasource? If it doesn't show this > > > > by default, is there a way to turn this on? > > > > > > > > I tried writing the code to obtain the JNDI resource (Spring context > > > > references), but it just says it can't find it (fails at "jdbc"), so > > > > perhaps my Resource definition was ignored, or my JNDI path is > > wrong. > > > > > > > > > > > > > > > > -- > > > Daniel Cunha > > > https://twitter.com/dvlc_ > > > http://www.tomitribe.com > > > http://www.tomitribe.io > > > >
