我尝试从我的数据源读取连接参数以建立JDBC连接。但我得到以下例外[1]
我正在使用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 :(得分:0)
错误在堆栈跟踪的第一行中描述。
java.lang.ClassCastException: org.jboss.as.connector.subsystems.datasources.WildFlyDataSource cannot be cast to javax.naming.Context
您正在对javax.sql.DataSource
进行查找,并尝试将其投放到javax.naming.Context
。