在web.xml配置引用数据源的时候,出现java.lang.reflect.InvocationTargetException异常

配置 web.xml 引用数据源的错误信息如下:

 

2011-6-27 21:28:34 org.apache.tomcat.util.digester.Digester endElement
严重: End event threw exception
java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:592)
 at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:928)
 at org.apache.catalina.startup.SetNextNamingRule.end(SetNextNamingRule.java:98)
 at org.apache.tomcat.util.digester.Rule.end(Rule.java:229)
 at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1138)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
 at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642)
 at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
 at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1076)
 at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4540)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:592)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
 at java.util.Hashtable.put(Hashtable.java:396)
 at org.apache.catalina.deploy.NamingResources.addResource(NamingResources.java:298)
 ... 35 more
2011-6-27 21:28:34 org.apache.catalina.startup.ContextConfig applicationWebConfig
严重: Parse error in application web.xml file at jndi:/localhost/MyDataSource/WEB-INF/web.xml
java.lang.NullPointerException
 at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2806)
 at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2832)
 at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1141)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
 at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642)
 at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
 at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1076)
 at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4540)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:592)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
 at java.util.Hashtable.put(Hashtable.java:396)
 at org.apache.catalina.deploy.NamingResources.addResource(NamingResources.java:298)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:592)
 at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:928)
 at org.apache.catalina.startup.SetNextNamingRule.end(SetNextNamingRule.java:98)
 at org.apache.tomcat.util.digester.Rule.end(Rule.java:229)
 at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1138)
 ... 27 more
2011-6-27 21:28:34 org.apache.catalina.startup.ContextConfig applicationWebConfig
严重: Occurred at line 12 column 18
2011-6-27 21:28:34 org.apache.catalina.startup.ContextConfig start

 

 

 

解决方案:

 

我出现此错误的原因是因为,在web.xml中配置引用数据源的时候,少配置了

<res-type>javax.sql.DataSource</res-type>

这个,所以,启动的Tomcat的时候,出现了空指针异常NullPotionException.

加上去就没事了..

 

启动成功!

 

 <!-- 引用数据源; -->
  <resource-ref>
  	<description>Oracle dataSource</description>
  	<res-ref-name>jdbc/DBSource</res-ref-name>
  	<res-type>javax.sql.DataSource</res-type>
  	<res-auth>Container</res-auth>
  	<res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>

 

 

你可能感兴趣的:(java,apache,tomcat,Web,xml)