maven jetty plugin 配置全局 jndi datasource

全局的datasource,要求把数据源配置在jetty.xml文件中,但是使用maven的插件,需要在pom.xml文件中指定jetty.xml文件在哪。同时,由于是全局的数据源,jetty会找不到数据库驱动,也需要在pom.xml文件中写上对数据库驱动的依赖。

此外,还需要配置一个webdefault.xml文件,这个文件是在web.xml文件加载之前加载的,可以把数据源的引用放在webdefault.xml文件中。同上,也需要在pom.xml文件中指定这个文件在哪。


1. 配置pom.xml文件

             <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.0.0.v20130308</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.13</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                    <jettyXml>src/test/resources/jetty.xml</jettyXml>
                    <webApp>
                        <defaultsDescriptor>src/test/resources/webdefault.xml</defaultsDescriptor>
                    </webApp>
                </configuration>
            </plugin>


2. 配置jetty.xml

    <New id="mysql" class="org.eclipse.jetty.plus.jndi.Resource">
     <Arg><Ref refid="Server"/></Arg>
     <Arg>jdbc/mysql</Arg>
     <Arg>
        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
           <Set name="Url">jdbc:mysql://localhost:3306/uns</Set>
           <Set name="User">root</Set>
           <Set name="Password">rachel</Set>
        </New>
     </Arg>
    </New>


3. 配置webdefault.xml

如果把数据源的引用配置在webdefault.xml文件中,那么就不需要在web.xml文件中配置了。如果不在webdefault.xml文件中引用数据源,那么就需要在每一个webapp中的web.xml文件中对其进行引用!

  <resource-ref>
    <description>MySQL DataSource Reference</description>
    <res-ref-name>jdbc/mysql</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

 

配好了!



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值