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