maven项目pom.xml配置
1、配置druid的jar依赖:
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>
2、配置jetty插件:
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <contextXml>${project.basedir}/src/test/resources/jetty-context.xml</contextXml>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppConfig>
                        <!--<contextPath>/example</contextPath>-->
                        <jettyEnvXml>${basedir}/src/test/resources/jetty-env.xml</jettyEnvXml>
                    </webAppConfig>
                    <httpConnector>
                        <port>8888</port>
                    </httpConnector>
                </configuration>
            </plugin>
jetty-context.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">
      
</Configure>
jetty-env.xml配置
 <New id="exampleDataSource" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg></Arg>
        <Arg>jdbc/EXAMPLE_DS</Arg>
        <Arg>
            <New class="com.alibaba.druid.pool.DruidDataSource">
                <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
                <Set name="url">jdbc:mysql://localhost:3306/dev_demo</Set>
                <Set name="username">root</Set>
                <Set name="password">root</Set>
                <Set name="initialSize">1</Set>
                <Set name="maxActive">1</Set>
                <Set name="maxWait">60000</Set>
                <Set name="minEvictableIdleTimeMillis">300000</Set>
            </New>
        </Arg>
         <Call name="bindToENC">
            <Arg>jdbc/EXAMPLE_DS</Arg>  <!-- binds jdbc/myds to java:comp/env/jdbc/myfoo for this webapp -->
        </Call>          
    </New>
spring的applicationContext.xml配置
   <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <!--EXAMPLE_DSwei为数据源名称-->
            <value>java:comp/env/jdbc/EXAMPLE_DS</value>
        </property>
    </bean>
    <bean id="dataSourceProxy" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
        <property name="targetDataSource" ref="dataSource" />
    </bean>
项目结构:

 
  
  
  
 
 
  
 
 
 