ofbiz使用mysql作为存储数据库


OFBiz是一个非常著名的电子商务平台,是一个非常著名的开源项目,提供了创建基于最新J2EE/XML规范和技术标准,构建大中型企业级、跨平台、跨数据库、跨应用服务器的多层、分布式电子商务类WEB应用系统的框架。 OFBiz最主要的特点是OFBiz提供了一整套的开发基于Java的web应用程序的组件和工具。包括实体引擎, 服务引擎, 消息引擎, 工作流引擎, 规则引擎等。OFBiz 已经正式成为 Apache 的顶级项目: Apache OFBiz。 ofbiz自带的数据库是Derby,这是一种小型的适合于测试系统的数据库,但不适合在产品级系统中使用,所以通常我们需要将ofbiz数据库迁移到其它数据库上。下面介绍迁移到mysql的步骤,迁移到其他数据库操作类似。

1. 安装mysql,创建ofbiz的数据库

使用以下命令分别创建ofbiz用户(密码ofbiz),和ofbiz、ofbizolap、ofbiztenant三个数据库

复制

mysql -u root 
create user 'ofbiz'@'localhost' identified by 'ofbiz';   
create database ofbiz DEFAULT CHARSET utf8mb4 COLLATE mb4_general_ci;  
create database ofbizolap DEFAULT CHARSET utf8mb4 COLLATE mb4_general_ci;  
create database ofbiztenant DEFAULT CHARSET utf8mb4 COLLATE mb4_general_ci;  
grant all on *.* to 'ofbiz'@'localhost';
flush privileges;
quit;

2. 修改ofbiz配置文件

编辑 entityengine.xml 修改默认的数据库引擎,以及连接数据库的用户名密码等信息

复制

# vim ofbiz_HOME/framework/entity/config/entityengine.xml

修改其中的delegator name标签为如下内容(即注释derby启用mysql)

<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
        <!-- <group-map group-name="org.ofbiz" datasource-name="localderby"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localderbyolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localderbytenant"/> -->
<group-map group-name="org.ofbiz" datasource-name="localmysql"/>

        <group-map group-name="org.ofbiz.olap" datasource-name="localmysqlolap"/>

        <group-map group-name="org.ofbiz.tenant" datasource-name="localmysqltenant"/>
        <!-- <group-map group-name="org.ofbiz" datasource-name="localpostnew"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localpostolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localposttenant"/> -->
    </delegator>
    <delegator name="default-no-eca" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" entity-eca-enabled="false" distributed-cache-clear-enabled="false">
        <!-- <group-map group-name="org.ofbiz" datasource-name="localderby"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localderbyolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localderbytenant"/> -->
<group-map group-name="org.ofbiz" datasource-name="localmysql"/>

        <group-map group-name="org.ofbiz.olap" datasource-name="localmysqlolap"/>

        <group-map group-name="org.ofbiz.tenant" datasource-name="localmysqltenant"/>
        <!-- <group-map group-name="org.ofbiz" datasource-name="localpostnew"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localpostolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localposttenant"/>  -->
    </delegator>

    <!-- be sure that your default delegator (or the one you use) uses the same datasource for test. You must run "ant load-demo" before running "ant run-tests" -->
    <delegator name="test" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main">
        <!-- <group-map group-name="org.ofbiz" datasource-name="localderby"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localderbyolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localderbytenant"/> -->
<group-map group-name="org.ofbiz" datasource-name="localmysql"/>

        <group-map group-name="org.ofbiz.olap" datasource-name="localmysqlolap"/>

        <group-map group-name="org.ofbiz.tenant" datasource-name="localmysqltenant"/>
        <!-- <group-map group-name="org.ofbiz" datasource-name="localpostnew"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localpostolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localposttenant"/>  -->
    </delegator>

修改datasource name部分注意修改数据库登陆信息及字符集和编码

复制

<datasource name="localmysql"
        helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
        field-type-name="mysql"
        check-on-start="true"
        add-missing-on-start="true"
        check-pks-on-start="false"
        use-foreign-keys="true"
        join-style="ansi-no-parenthesis"
        alias-view-columns="false"
        drop-fk-use-foreign-key-keyword="true"
        table-type="InnoDB"
        character-set="utf8"
        collate="utf8_general_ci">
    <read-data reader-name="tenant"/>
    <read-data reader-name="seed"/>
    <read-data reader-name="seed-initial"/>
    <read-data reader-name="demo"/>
    <read-data reader-name="ext"/>
    <read-data reader-name="ext-test"/>
    <read-data reader-name="ext-demo"/>
    <inline-jdbc
            jdbc-driver="com.mysql.jdbc.Driver"
            jdbc-uri="jdbc:mysql://127.0.0.1:3306/ofbiz?autoReconnect=true"
            jdbc-username="ofbiz"
            jdbc-password="ofbiz"
            isolation-level="ReadCommitted"
            pool-minsize="2"
            pool-maxsize="250"
            time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MySQL
            and had to set it to -1 in order to avoid this issue.
            For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
    <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
</datasource>
    
 <datasource name="localmysqlolap"
        helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
        field-type-name="mysql"
        check-on-start="true"
        add-missing-on-start="true"
        check-pks-on-start="false"
        use-foreign-keys="true"
        join-style="ansi-no-parenthesis"
        alias-view-columns="false"
        drop-fk-use-foreign-key-keyword="true"
        table-type="InnoDB"
        character-set="utf8"
        collate="utf8_general_ci">
    <read-data reader-name="tenant"/>
    <read-data reader-name="seed"/>
    <read-data reader-name="seed-initial"/>
    <read-data reader-name="demo"/>
    <read-data reader-name="ext"/>
    <read-data reader-name="ext-test"/>
    <read-data reader-name="ext-demo"/>
    <inline-jdbc
            jdbc-driver="com.mysql.jdbc.Driver"
            jdbc-uri="jdbc:mysql://127.0.0.1:3306/ofbizolap?autoReconnect=true"
            jdbc-username="ofbiz"
            jdbc-password="ofbiz"
            isolation-level="ReadCommitted"
            pool-minsize="2"
            pool-maxsize="250"
            time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MySQL
            and had to set it to -1 in order to avoid this issue.
            For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
     <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
</datasource>
    
<datasource name="localmysqltenant"
        helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
        field-type-name="mysql"
        check-on-start="true"
        add-missing-on-start="true"
        check-pks-on-start="false"
        use-foreign-keys="true"
        join-style="ansi-no-parenthesis"
        alias-view-columns="false"
        drop-fk-use-foreign-key-keyword="true"
        table-type="InnoDB"
        character-aracter-set="utf8"
        collate="utf8_general_ci">
    <read-data reader-name="tenant"/>
    <read-data reader-name="seed"/>
    <read-data reader-name="seed-initial"/>
    <read-data reader-name="demo"/>
    <read-data reader-name="ext"/>
    <read-data reader-name="ext-test"/>
    <read-data reader-name="ext-demo"/>
    <inline-jdbc
            jdbc-driver="com.mysql.jdbc.Driver"
            jdbc-uri="jdbc:mysql://127.0.0.1:3306/ofbiztenant?autoReconnect=true"
            jdbc-username="ofbiz"
            jdbc-password="ofbiz"
            isolation-level="ReadCommitted"
            pool-minsize="2"
            pool-maxsize="250"
            time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MySQL
            and had to set it to -1 in order to avoid this issue.
            For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
    <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
</datasource>

复制 mysql.jar 文件到指定目录 mysql.jar 下载地址:http://dev.mysql.com/downloads/connector/j/ 复制mysql.jar到lib目录

复制

cp mysql-connector-java-5.1.36-bin.jar ofbiz_HOME/framework/base/lib/</pre>

3. 导入数据,启动ofbiz

复制

cd ofbiz_HOME
./ant load-demo           #导入demo数据
./ant start               #启动ofbiz

至此已经完成ofbiz使用mysql数据库的配置,其他操作请参考ofbiz目录下的README文件

优质内容筛选与推荐>>
1、中国非正常死亡最高的行业 TOP 10
2、OWASP top 10 (2017) 学习笔记--安全错误配置
3、coderforces 721b
4、best-time-to-buy-and-sell-stock
5、ExtJs双ActionResult共用同一Js文件ID冲突解决方案


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号