WSO2-APIM / IS如何在JNDI组件

时间:2017-02-25 05:38:59

标签: wso2 wso2is wso2-am

我正在编写一个自定义身份验证器,它需要在启动时从JNDI查找数据源。我在启动时遇到NameNotFoundException错误

[2017-02-25 12:01:39,071] [Component Resolve Thread] ERROR {com.kbank.carbon.identity.authenticator.KBankAuthenticator} -  Exception while looking up datasource[jdbc/API_SERVICE_DB] 
javax.naming.NameNotFoundException: Name [jdbc/API_SERVICE_DB] is not bound in this Context. Unable to find [jdbc].
    at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
    at org.wso2.carbon.context.internal.CarbonContextDataHolder$CarbonInitialJNDIContext.lookup(CarbonContextDataHolder.java:709)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.kbank.carbon.identity.authenticator.KBankAuthenticator.getDataSource(KBankAuthenticator.java:478)
    at com.kbank.carbon.identity.authenticator.KBankAuthenticator.<clinit>(KBankAuthenticator.java:79)
    at com.kbank.carbon.identity.authenticator.internal.KBankAuthenticatorServiceComponent.activate(KBankAuthenticatorServiceComponent.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
    at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
    at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
    at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
    at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
    at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
    at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
    at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
    at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
    at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
    at java.lang.Thread.run(Thread.java:745)

我使用以下代码查找数据源。

DataSource dataSource = (DataSource) new InitialContext().lookup(dsName);

如果我将此代码从静态块/构造函数中移出并放入方法中,则可以正常工作。

我认为这是因为我的自定义身份验证器是在JNDI(或JDBC)功能之前加载的。如何在启动期间从JNDI创建自定义身份验证器查找数据源。

非常感谢。

0 个答案:

没有答案