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>
  • 相关阅读:
    代理服务器的原理及用法
    [Web前端] 给li设置float浮动属性之后,无法撑开外层ul的问题。
    [Web 前端] react-router4-0中文文档
    [Web 前端] inline-block元素设置overflow:hidden属性导致相邻行内元素向下偏移
    [Web 前端] React Js img 图片显示默认 占位符
    [Web 前端] React高级教程(es6)——(2)对于Refs最新变动的理解
    [Web 前端] 你不知道的 React Router 4
    [Web 前端] React-router4简约教程
    [Web 前端] React Router v4 入坑指南
    [Web 前端] 前端频道之团队维护、聚合、订阅
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/7866006.html
Copyright © 2011-2022 走看看