初学SSH,就遇到了很多人都遇到的问题。我是照着李兴华老师的智囊团项目弄得,在第一个注册页就出现了这个问题各种百度,Google都没法得以解决有说配置文件错的,有说JAR包冲突的。日志文件如下:2009-5-10 11:20:27 org.apache.catalina.startup.HostConfig checkResources
信息: Reloading context [/MyKnownProject]
2009-05-10 11:20:31,640 INFO [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/MyKnownProject]] - Initializing Spring root WebApplicationContext
2009-05-10 11:20:31,640 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
2009-05-10 11:20:31,781 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@17d57d6: display name [Root WebApplicationContext]; startup date [Sun May 10 11:20:31 CST 2009]; root of context hierarchy
2009-05-10 11:20:32,218 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/classes/applicationContext.xml]
2009-05-10 11:20:34,671 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@17d57d6]: org.springframework.beans.factory.support.DefaultListableBeanFactory@b09321
2009-05-10 11:20:35,000 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b09321: defining beans [dataSource,sessionFactory,hibernateTemplate,iuserdao,iuserdaoimpl]; root of factory hierarchy
2009-05-10 11:20:35,156 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b09321: defining beans [dataSource,sessionFactory,hibernateTemplate,iuserdao,iuserdaoimpl]; root of factory hierarchy
2009-05-10 11:20:35,171 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Caused by: 
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3951)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4225)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1089)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1187)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:292)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1305)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1569)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1558)
at java.lang.Thread.run(Thread.java:595)
2009-05-10 11:20:35,171 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/MyKnownProject]] - StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Caused by: 
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:93)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:197)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:184)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1202)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:428)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:292)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1305)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1569)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1558)
at java.lang.Thread.run(Thread.java:595)

解决方案 »

  1.   

    2009-05-10 11:20:35,171 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/MyKnownProject]] - Servlet /MyKnownProject threw load() exception
    javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:197)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:184)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1202)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:428)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
    at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:82)
    at javax.servlet.GenericServlet.init(GenericServlet.java:211)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
    2009-05-10 11:20:36,234 INFO [org.springframework.web.struts.ContextLoaderPlugIn] - ContextLoaderPlugIn for Struts ActionServlet 'action, module '': initialization started
    2009-05-10 11:20:36,234 INFO [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/MyKnownProject]] - Initializing WebApplicationContext for Struts ActionServlet 'action', module ''
    2009-05-10 11:20:36,234 ERROR [org.springframework.web.struts.ContextLoaderPlugIn] - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
    Caused by: 
    javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:93)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:197)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:184)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1202)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:428)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
    at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:82)
    at javax.servlet.GenericServlet.init(GenericServlet.java:211)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3951)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4225)
    at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1089)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1187)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:292)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1305)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1569)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1558)
    at java.lang.Thread.run(Thread.java:595)
    2009-05-10 11:20:36,250 INFO [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/MyKnownProject]] - Marking servlet action as unavailable
    2009-05-10 11:20:36,250 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/MyKnownProject]] - Servlet /MyKnownProject threw load() exception
    javax.servlet.UnavailableException
    at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:880)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
    at javax.servlet.GenericServlet.init(GenericServlet.java:211)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
      

  2.   

    项目没有成功启动,原因是Name jdbc is not bound in this Context,
    应该你没有配置名叫jdbc的数据源
      

  3.   

    这是server.xml的配置。。  <Logger className="org.apache.catalina.logger.FileLogger"
     prefix="localhost_MysqlTest_log." suffix=".txt"
     timestamp="true"/>
     
    <Context path="/known" docBase="E:\MyKnownProject\MyKnownProject\WebRoot"
    debug="5" reloadable="true" crossContext="true">
      <Resource name="jdbc/known"  auth="Container" type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/known">
    <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>100</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>30</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>root</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>102938</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/known</value>
    </parameter>
      </ResourceParams>
    </Context>
      

  4.   

    这是spring.xml<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="dataSource"
    class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/known"></property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    <!-- 允许自动提交 -->
    <prop key="hibernate.connection.autocommit">true</prop>
    <!-- 显示SQL语句 -->
    <prop key="hibernate.show_sql">false</prop> </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/lyp/known/vo/User.hbm.xml</value>
    </list>
    </property>
    </bean>
    <!-- hibernate模板操作配置,连接session工厂 -->
    <bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="iuserdao" class="com.lyp.known.dao.IUserDAO"
    abstract="true">
    </bean>
    <bean id="iuserdaoimpl"
    class="com.lyp.known.dao.impl.IUserDAOImpl">
    <property name="hibernateTemplate">
    <ref bean="hibernateTemplate" />
    </property>
    </bean></beans>
      

  5.   

    这是struts-config.xml....<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
    <data-sources />
    <form-beans>
    <form-bean name="userForm"
    type="com.lyp.known.struts.form.UserForm" /> </form-beans> <global-exceptions />
    <global-forwards />
    <action-mappings>
    <action attribute="userForm" input="/jsp/errors.jsp"
    name="userForm" parameter="status" path="/jsp/user" scope="request"
    type="com.lyp.known.struts.action.UserAction">
    <forward name="registersuccess" path="/jsp/index.jsp"></forward>
    <forward name="registerfailure" path="/jsp/register.jsp"></forward>
    </action> </action-mappings>
    <!-- STRUTS与SPRING 合体-->
    <controller
    processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
    </controller>
    <message-resources
    parameter="com.lyp.known.struts.ApplicationResources" />
    <plug-in
    className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation"
    value="/WEB-INF/classes/applicationContext.xml" />
    </plug-in>
    </struts-config>
      

  6.   

    server.xml里的jdbc配置去掉,统一在spring的配置文件里配置!
      

  7.   

    这种配置也要在web.xml进行配置的
    <resource-ref>
    <description>DBConnection</discription>
    <res-ref-name>jdbc/know</res-ref-name>
    <res-type>java.sql.DataSource</res-tye>
    <res-auth>Container</res-auth>
    </resource-ref>