如何为TomEE +设置DataSource

时间:2016-06-15 13:04:28

标签: java netbeans ejb mariadb tomee

我一直在试图弄清楚如何设置NetBeans(v8.1)和TomEE +(v1.7.4)来使用EJB访问数据。

我一直关注The NetBeans E-commerce Tutorial(Affable Bean应用),我被Accessing Data with EJBs困住了。是否所有编辑都在教程中说明并在运行时出错。

AffableBean日志:

build-impl.xml:1045: The module has not been deployed.
See the server log for details.

Apache TomEE + 1。7。4日志:

Jun 15, 2016 8:26:14 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet ControllerServlet as unavailable
Jun 15, 2016 8:26:14 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [ControllerServlet] in web application [/AffableBean] threw load() exception
javax.naming.NameNotFoundException: Name [controller.ControllerServlet/categoryFacade] is not bound in this Context. Unable to find [controller.ControllerServlet].

Apache TomEE + 1.7.4:

INFO: Configuring PersistenceUnit(name=AffableBeanPU)
Jun 15, 2016 8:26:11 AM org.apache.openejb.config.AutoConfig deploy
WARNING: Found matching datasource: web/connpool but this one is not a JTA datasource
Jun 15, 2016 8:26:11 AM org.apache.openejb.config.AutoConfig deploy
WARNING: Found matching datasource: web/connpool but this one is not a JTA datasource
Jun 15, 2016 8:26:11 AM org.apache.tomee.catalina.TomcatWebAppBuilder startInternal
SEVERE: Unable to deploy collapsed ear in war StandardEngine[Catalina].StandardHost[localhost].StandardContext[/AffableBean]
org.apache.openejb.OpenEJBException: PeristenceUnit AffableBeanPU <jta-data-source> points to a non jta managed Resource.  Update Resource "connpool" to "JtaManaged=true", use a different Resource, or delete the <jta-data-source> element and a default will be supplied if possible.

我的persistence.xml代码按照教程,即:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="AffableBeanPU" transaction-type="JTA">
    <jta-data-source>connpool</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
        <property name="eclipselink.logging.level" value="FINEST"/>
  </persistence-unit>
</persistence>

所以我的问题是,如何在我的IDE中设置DataSource / EJB,以便它可以在我的服务器上运行?无论Netbeans电子商务教程如何。

编辑:坚持Accessing Data with EJBs

1 个答案:

答案 0 :(得分:1)

您可以将数据源定义为全局数据源(适用于所有Web应用程序),在$ TOMEE / conf / tomee.xml文件中定义或特定于$ WEBAPP / WEB-INF / resources.xml文件中的webapp,就像这样

webapp的src / META-INF目录中的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence
    version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="xyz">
        <jta-data-source>xyz</jta-data-source>
        <properties>
            <property
                name="openjpa.jdbc.DBDictionary"
                value="org.apache.openjpa.jdbc.sql.OracleDictionary" />
            <property
                name="openjpa.jdbc.DBDictionary"
                value="oracle(maxEmbeddedBlobSize=-1,maxEmbeddedClobSize=-1)" />
            <property
                name="openjpa.jdbc.SynchronizeMappings"
                value="buildSchema(ForeignKeys=true)" />
        </properties>
    </persistence-unit>
</persistence>

和$ WEBAPP / WEB-INF / resource.xml

中定义的数据源
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
    <Resource
        id="xyz"
        type="DataSource">
        JdbcDriver oracle.jdbc.OracleDriver
        JdbcUrl jdbc:oracle:thin:@localhost:1521:XE
        UserName myuser
        Password mypass
        JtaManaged true
        TestOnBorrow false
        MaxActive 20        
    </Resource>    
</tomee>

请参阅http://tomee.apache.org/datasource-config.htmlhttp://tomee.apache.org/common-datasource-configurations.html

相关问题