调用init方法失败;嵌套异常是javax.naming.NameNotFoundException

时间:2017-03-15 11:50:20

标签: mysql spring maven tomcat tomcat8.5

错误日志:

        <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
      <display-name>RestfulWebService</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
      </welcome-file-list>
      <!-- The definition of the Root Spring Container shared by all Servlets and Filters - Starts -->
      <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/root-context.xml</param-value>
      </context-param>
      <!-- The definition of the Root Spring Container shared by all Servlets and Filters - Ends -->  

    <!-- Creates the Spring Container shared by all Servlets and Filters - Starts -->
      <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <!-- User Session Handling - Starts 
      <listener>
          <listener-class>com.ericsson.utility.UserSessionListener</listener-class>
      </listener>-->
      <session-config>
            <session-timeout>45</session-timeout>
      </session-config>
    <!-- User Session Handling - Ends -->
    <!-- Spring Processes application requests -Starts -->
      <servlet>
          <servlet-name>OredooWalletServlet</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <init-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>
              /WEB-INF/EngineConfig/rest-context.xml
              </param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
          <servlet-name>OredooWalletServlet</servlet-name>
          <url-pattern>/owp/*</url-pattern>
      </servlet-mapping>
    </web-app>

我的web.xml

                <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:context="http://www.springframework.org/schema/context"
                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.xsd
                                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

                <context:annotation-config></context:annotation-config>

             <!--  Read from Properties file 
             <bean id="reportingProperties"
                    class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
                    <property name="locations">
                        <list>
                            <value>classpath*:owpsimulator.properties</value>
                        </list>
                    </property>
                    <property name="ignoreUnresolvablePlaceholders" value="true"/>
            </bean>  -->
             <!-- Create DataSource Bean-Starts -->
                <bean id="appDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
                    <property name="jndiName" value="java:comp/env/jdbc/test"/>
                </bean>  
             <!-- Create DataSource Bean-Ends -->   
            <!-- Create DataSource Bean-Ends -->   
            <!-- JdbcTemplate -Starts -->
                   <bean id="jdbcTemplate"  class="org.springframework.jdbc.core.JdbcTemplate">
                     <property name="fetchSize" value="100"/>
                     <property name="dataSource" ref="appDatasource"/>
                   </bean>  
             <!-- JdbcTemplate -Ends -->
             <!-- NamedParameterJdbcTemplate -Starts -->
                   <bean id="namedParameterJdbcTemplate"  class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
                      <constructor-arg ref="jdbcTemplate"/>
                   </bean>  
             <!-- NamedParameterJdbcTemplate -ends -->

            </beans>

我的root-context.xml

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/test" password="root" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/test" username="root"/>

我用spring,mysql和jdbc模板创建了一个REST Web服务。我添加了mysql连接器jar。我也在pom.xml中包含了mysql。

在tomcat server.xml中,我添加了<ResourceLink name="jdbc/test" global="jdbc/test" type="javax.sql.DataSource" />

但我仍然无法找到此错误的来源。

javax.naming.NameNotFoundException添加到tomcat的context.xml后,我没有收到异常stroke-dashoffset: 1000; stroke-dasharray: 10; @keyframes dash { to { stroke-dashoffset: 0; stroke-dasharray: 10; } } ,但我的ResourceMapping无效。

0 个答案:

没有答案