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:
|
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参考: