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>

 

转载于:https://www.cnblogs.com/tonggc1668/p/7866097.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值