zoukankan      html  css  js  c++  java
  • tomcat jndi 数据源

    web.xml

      <!-- ================================================================================ -->
      <!-- jndi configure -->
      <!-- ================================================================================ -->
      <resource-ref> <!-- adapt weblogic server  -->
        <res-ref-name>jndi_base</res-ref-name>
        <res-auth>Container</res-auth>
        <mapped-name>jndi_wmsc</mapped-name>
      </resource-ref>

    webapp文件夹下META-INF文件夹下context.xml

    <?xml version='1.0' encoding='utf-8'?>
    <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <!-- The contents of this file will be loaded for each web application -->
    <Context>
    
        <!-- Default set of monitored resources -->
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
    
        <!-- Uncomment this to disable session persistence across Tomcat restarts -->
        <!--
        <Manager pathname="" />
        -->
    
        <!-- Uncomment this to enable Comet connection tacking (provides events
             on session expiration as well as webapp lifecycle) -->
        <!--
        <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
        -->
        <!--测试环境YD_SERVER数据库连接地址 -->
        <Resource name="jndi_wmsc" auth="Container" type="javax.sql.DataSource"  maxActive="100" maxIdle="30" maxWait="10000" username="ggs" password="mxDUF6IgMjEq3ClI" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://10.19.105.234:3306/wmsc?characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull" />
    </Context>

    applicationContext.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" 
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:tx="http://www.springframework.org/schema/tx" 
        xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:aop="http://www.springframework.org/schema/aop" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:task="http://www.springframework.org/schema/task"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
    
    
        <mvc:annotation-driven />     
        <tx:annotation-driven transaction-manager="transactionManager" /> 
        <aop:aspectj-autoproxy proxy-target-class="true"/>
        
        <!--  JNDI数据源-->    
         <jee:jndi-lookup id="dataSource" jndi-name="jndi_wmsc" resource-ref="true"/>
    
        <!-- SPRING JDBC -->
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSource" />
        </bean>
        <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
            <constructor-arg ref="dataSource"/> 
        </bean>
        
        <!-- SPRING 事务管理-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>    
        
      
    </beans>
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:tx="http://www.springframework.org/schema/tx" 
        xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:aop="http://www.springframework.org/schema/aop" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:task="http://www.springframework.org/schema/task"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
    
    <import resource="spring-quartz.xml"/>
    
        <mvc:annotation-driven />     
        <tx:annotation-driven transaction-manager="transactionManager" /> 
        <task:annotation-driven/>  
        <aop:aspectj-autoproxy proxy-target-class="true"/>
        
        <!--  加载配置文件-->
       <!--  <context:property-placeholder location="classpath:config.properties"/> -->
        
        <!--  JNDI数据源-->    
         <jee:jndi-lookup id="dataSource" jndi-name="jndi_wmsc" resource-ref="true"/>
    
        <!-- SPRING JDBC -->
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSource" />
        </bean>
        <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
            <constructor-arg ref="dataSource"/> 
        </bean>
        
        <!-- SPRING 事务管理-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>    
        
        <!--  应用上线文初始化Bean-->
        <bean class="com.yd.common.runtime.CIPRuntimeContextInitializer" /> 
        
        <!-- dao,service,controller,component scan -->
        <!-- <context:component-scan base-package="com.yd.wmsc" />
        <context:component-scan base-package="com.yd.common.function" />
        <context:component-scan base-package="com.yd.common.auth" /> -->
        
        <context:component-scan base-package="com.yd.wmsc,com.yd.common.function,com.yd.common.auth"  >
                <context:exclude-filter type="annotation" 
                expression="org.springframework.stereotype.Controller"/>
        </context:component-scan>
    
    </beans>
  • 相关阅读:
    VS2010中ActiveX控件"未能实例化activex控件 因为这需要设计时授权"解决办法
    CreateThread,_beginthread与AfxbeginThread之间的区别
    C的定时器timeSetEvent使用
    GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别
    使用PostThreadMessage在Win32线程间传递消息
    c++配置文件.ini,GetPrivateProfileString( )WritePrivateProfileString( )
    Callback函数详解
    Dispose,using
    mysql 存储过程,表
    函数,视图,存储过程,触发器,sysobjects (系统对象表),事务,异常
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/7866006.html
Copyright © 2011-2022 走看看