Tomee数据源的配置方式

TomEE Philosophy

Apache TomEE, pronounced "Tommy", is an all-Apache Java EE 6 Web Profile certified stack where Tomcat is top dog. Apache TomEE is assembled from a vanilla Apache Tomcat zip file. We start with Tomcat, add our jars and zip up the rest. The result is Tomcat with added EE features - TomEE.

Its core values are:

  • Be Tomcat

  • Be certified

  • Be small

Tomee是在tomcat的基础上,加上一些jar包,增加EE的特性。

配置tomee的数据源和tomcat有很大的区域,按照说明文档,我们可以在两个位置:

1、tomee目录下conf/tomee.xml下。

2、自己的web部署目录下WEB-INF/resources.xml

我这里以连接mysql数据库为例,其他数据库可以根据情况修改。

在tomee.xml中,增加如下:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->

  <!-- activate next line to be able to deploy applications in apps -->
  <!-- <Deployments dir="apps" /> -->
    <Resource id="jdbc/plsDS" type="javax.sql.DataSource">#Sat Nov 17 11:44:11 CST 2018
jdbcDriver=com.mysql.jdbc.Driver
password=123456
userName=pls
jdbcUrl=jdbc\:mysql\://localhost\:3306/eedata?zeroDateTimeBehavior\=convertToNull
</Resource>
</tomee>

WEB-INF/resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <Resource id="jdbc/plsDS" type="javax.sql.DataSource">#Sat Nov 17 11:44:11 CST 2018
jdbcDriver=com.mysql.jdbc.Driver
password=123456
userName=pls
jdbcUrl=jdbc\:mysql\://localhost\:3306/eedata?zeroDateTimeBehavior\=convertToNull
</Resource>
</resources>

注意:这里的数据库连接设置采用属性key=value的方式。

我在jpa的使用如下。

由于tomee已经是ee服务器,使用我们可以使用JTA,我们在jpa可以进行如下配置。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="com.yjk_tomeeweb_war_1.0-SNAPSHOTPU" transaction-type="JTA">
    <jta-data-source>jdbc/plsDS</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

tomee参考:

http://tomee.apache.org/refcard/refcard.html

http://tomee.apache.org/containers-and-resources.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值