jetty jndi数据源

applicationContext.xml

<?xml version="1.0" encoding="utf-8"?>
<beans default-init-method="init" default-destroy-method="destroy"
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    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
                           http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
                           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
       
       <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations" value="classpath:database.properties"/>
    </bean>
    
    <!-- jndi --> 
    <bean id="dataSourceMaster" class="org.springframework.jndi.JndiObjectFactoryBean"> 
        <property name="jndiName"> 
            <value>wms</value> 
        </property>
        <property name="resourceRef"> 
            <value>true</value> 
        </property>
    </bean>
    
    <bean id="dataSourceSlave" class="org.springframework.jndi.JndiObjectFactoryBean"> 
        <property name="jndiName"> 
            <value>wmsSlave</value> 
        </property>
        <property name="resourceRef"> 
            <value>true</value> 
        </property>
    </bean>
    
    <bean id="dataSource" class="com.yundaex.wms.config.DynamicDataSource" >  
        <property name="targetDataSources">  
            <map key-type="java.lang.String">  
                <entry value-ref="dataSourceMaster" key="dataSourceMaster"></entry>  
                <entry value-ref="dataSourceSlave" key="dataSourceSlave"></entry>  
            </map>  
        </property>  
        <property name="defaultTargetDataSource" ref="dataSourceMaster" >  
        </property>  
    </bean> 
    
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    
    <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg name="classicJdbcTemplate">
            <ref bean="jdbcTemplate"/>
        </constructor-arg>
    </bean>
    
    
    <bean id="dynamicDataSourceAspect" class="com.yundaex.wms.config.aop.DynamicDataSourceAspect"  />

    <aop:config>
          <aop:aspect ref="dynamicDataSourceAspect">
             <aop:pointcut id="backMethod"   
                expression="execution(public * com.yundaex.wms..CompleteInboundNoticeBackToQimenDao.query*(..))
                 || execution(public * com.yundaex.wms..InventoryCountReportToQimenDao.query*(..))
                  || execution(public * com.yundaex.wms..OrderProcessReportToQimenDao.query*(..))
                  || execution(public * com.yundaex.wms..OutboundNoticeConfirmBackToQimenDao.query*(..))
                   || execution(public * com.yundaex.wms..ReturnOrderBackToQimenDao.query*(..))
                    || execution(public * com.yundaex.wms..StockChangeReportToQimenDao.query*(..))
                  || execution(public * com.yundaex.wms..CompleteInboundNoticeBackToCainiaoDao.query*(..))
                 || execution(public * com.yundaex.wms..InventoryCountReportToCainiaoDao.query*(..))
                  || execution(public * com.yundaex.wms..OrderProcessReportToCainiaoDao.query*(..))
                  || execution(public * com.yundaex.wms..OutboundNoticeConfirmBackToCainiaoDao.query*(..))
                    "/>  
             <aop:around method="aroundMethod"  pointcut-ref="backMethod"/>
          </aop:aspect>
    </aop:config>       
     
    <mvc:annotation-driven />
    <context:component-scan base-package="com.yundaex.wms" />
    <!-- 配置事务管理 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>

    <!-- 配置注解实现管理事务 -->
    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="true" />
</beans>

WEB-INF文件夹下jetty-env.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <!-- 应用数据源 -->
    <New id="wmsMasterDataSource" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>wms</Arg>
        <Arg>
            <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
                <Set name="url">jdbc:mysql://10.19.105.161:3306/wms?useUnicode=true&amp;characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull&amp;rewriteBatchedStatements=true</Set>
                <Set name="username">ggs</Set>
                <Set name="password">UGTVDYTXVSIN</Set>
                <Set name="maxActive">500</Set>
            </New>
        </Arg>
    </New>
    <New id="wmsSlaveDataSource" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>wmsSlave</Arg>
        <Arg>
           <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
                <Set name="url">jdbc:mysql://10.19.105.184:3306/wms?useUnicode=true&amp;characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull&amp;rewriteBatchedStatements=true</Set>
                <Set name="username">ggs</Set>
                <Set name="password">ZPIOSVYLXMNI</Set>
                <Set name="maxActive">500</Set>
            </New>
        </Arg>
    </New>
    <Set name="maxFormContentSize">2000000</Set>
</Configure>

 

posted @ 2017-11-20 14:24  tonggc1668  阅读(174)  评论(0编辑  收藏  举报