2016-07-15 21 views
0

JDBC接続を作成するために、データソースから接続パラメータを読み取ろうとしています。しかし、私は例外[1]WildFlyDataSourceはjavax.naming.Contextにキャストできません

イムのような試みてwildfly 10.xの

イムを使用して、次の取得します。

Context initCtx = new InitialContext(); 
Context envCtx = (Context) initCtx.lookup("java:jboss/datasources/myDS"); 

// Look up our data source 
DataSource ds = (DataSource) 
envCtx.lookup("java:/testdb"); 

誰でも私を助けることができますか?

[1]

16:44:05,140 ERROR [stderr] (ServerService Thread Pool -- 68) java.lang.ClassCastException: org.jboss.as.connector.subsystems.datasources.WildFlyDataSource cannot be cast to javax.naming.Context 
16:44:05,140 ERROR [stderr] (ServerService Thread Pool -- 68) at com.cdi.crud.infra.rest.RestApplication.initialize(RestApplication.java:117) 
16:44:05,140 ERROR [stderr] (ServerService Thread Pool -- 68) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
16:44:05,140 ERROR [stderr] (ServerService Thread Pool -- 68) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
16:44:05,140 ERROR [stderr] (ServerService Thread Pool -- 68) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
16:44:05,140 ERROR [stderr] (ServerService Thread Pool -- 68) at java.lang.reflect.Method.invoke(Method.java:497) 
16:44:05,141 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98) 
16:44:05,141 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81) 
16:44:05,141 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:126) 
16:44:05,141 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.resteasy.cdi.JaxrsInjectionTarget.postConstruct(JaxrsInjectionTarget.java:77) 
16:44:05,141 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:171) 
16:44:05,141 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96) 
16:44:05,141 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.bean.ContextualInstanceStrategy$ApplicationScopedContextualInstanceStrategy.get(ContextualInstanceStrategy.java:141) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at com.cdi.crud.infra.rest.RestApplication$Proxy$_$$_WeldClientProxy.getClasses(Unknown Source) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.resteasy.spi.ResteasyDeployment.processApplication(ResteasyDeployment.java:485) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:331) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:245) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:113) 
16:44:05,142 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:231) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:132) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:526) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:101) 
16:44:05,143 ERROR [stderr] (ServerService Thread Pool -- 68) at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82) 
16:44:05,144 ERROR [stderr] (ServerService Thread Pool -- 68) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
16:44:05,144 ERROR [stderr] (ServerService Thread Pool -- 68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
16:44:05,144 ERROR [stderr] (ServerService Thread Pool -- 68) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
16:44:05,144 ERROR [stderr] (ServerService Thread Pool -- 68) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
16:44:05,144 ERROR [stderr] (ServerService Thread Pool -- 68) at java.lang.Thread.run(Thread.java:745) 
16:44:05,144 ERROR [stderr] (ServerService Thread Pool -- 68) at org.jboss.threads.JBossThread.run(JBossThread.java:320) 
16:44:05,148 INFO [o 

答えて

0

エラーがスタックトレースの1行目に記載されています。

java.lang.ClassCastException: org.jboss.as.connector.subsystems.datasources.WildFlyDataSource cannot be cast to javax.naming.Context 

あなたはjavax.sql.DataSource上で検索を行うと、javax.naming.Contextにキャストしようとしています。

+0

ありがとうございました。コンテキストinitCtx =新しいInitialContext(); \t \t \tデータソースds =(データソース)initCtx.lookup( "java:jboss/datasources/lobDS"); – Ratha

関連する問題