JNDI @Resource not found in Wildfly 10 -
i'm trying access jndi oracle datasource through @resource annotation in resteasy webservice on wildfly 10, null returned. works initialcontext.lookup method. java code:
@path("/rest") public class servicetest { @resource(name = "jdbc/oracleds") datasource source1; @resource(name = "java:/jdbc/oracleds") datasource source2; @resource(lookup = "java:/jdbc/oracleds") datasource source3; @get @path("/test") @produces(mediatype.text_plain) public string testjndi () { try { javax.naming.context initctx = new initialcontext(); datasource source4 = (datasource)initctx.lookup("java:/jdbc/oracleds"); initctx.close(); return "" + source1 + " / " + source2 + " / " + source3 + " / " + source4; } catch (exception error) { e.printstacktrace(); } }
this standalone.xml datasource definition:
<datasource jta="true" jndi-name="java:/jdbc/oracleds" pool-name="oracleds" enabled="true" use-ccm="true" statistics-enabled="true"> <connection-url> jdbc:oracle:thin:@192.168.10.20:1521:log </connection-url> <driver-class>oracle.jdbc.driver.oracledriver</driver-class> <driver>oracle</driver> <pool> <initial-pool-size>1</initial-pool-size> <max-pool-size>10</max-pool-size> </pool> <security> <user-name>user</user-name> <password>passw</password> </security> <validation> <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.oraclevalidconnectionchecker"/> <background-validation>true</background-validation> <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.oraclestaleconnectionchecker"/> <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.oracleexceptionsorter"/> </validation> <timeout> <blocking-timeout-millis>30000</blocking-timeout-millis> <idle-timeout-minutes>15</idle-timeout-minutes> <query-timeout>300</query-timeout> </timeout> <statement> <track-statements>nowarn</track-statements> </statement> </datasource>
and module.xml code:
<?xml version="1.0" encoding="utf-8"?> <module xmlns="urn:jboss:module:1.1" name="com.oracle"> <resources> <resource-root path="ojdbc6.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
the service output this:
null / null / null / org.jboss.as.connector.subsystems.datasources.wildflydatasource@4b1881
why source4 founds resource , others not? expected @ least source3 source4. wrong in @resource definition?
thanks
make sure have beans.xml
in web-inf dir.
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans>
Comments
Post a Comment