日期:2014-05-16  浏览次数:20831 次

broadleaf commerce到mysql和tomcat的迁移

    最近刚刚接触broadleaf commerce, 一个电商网站的开源模版。具体的运行和配置可以参考链接:点击打开链接

而该模版是在jetty容器下运行的,数据库是HSQL。官方网站上给出了如何将数据库迁移到mysql以及把项目工程部署在tomcat中所需要的配置,但是过程不甚详细,网上这方面的资源也不是很多,所以楼主就打算写这篇博客作为一个总结。

1.数据库的迁移(HSQL到MYSQL)

(a)打开DemoSite工程的根目录下pom.xml文件,在<dependencyManagement>区域中添加:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.26</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency> 
(b)分别在admin和site文件夹中找到pom.xml打开并在<dependencies>区域中添加:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency> 
(c)在mysql数据库中添加database名为broadleaf

(d)分别打开admin/src/main/webapp/META-INF和admin/src/main/webapp/META-INF中的context.xml,将内容替换如下(数据库相关的配置信息如用户名和密码请根据自身的环境作相应的修改):

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource name="jdbc/web"
              auth="Container"
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              testWhileIdle="true"
              testOnBorrow="true"
              testOnReturn="false"
              validationQuery="SELECT 1"
              timeBetweenEvictionRunsMillis="30000"
              maxActive="15"
              maxIdle="10"
              minIdle="5"
              removeAbandonedTimeout="60"
              removeAbandoned="false"
              logAbandoned="true"
              minEvictableIdleTimeMillis="30000"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
              username="root"
              password="123"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/broadleaf"/>

    <Resource name="jdbc/storage"
              auth="Container"
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              testWhileIdle="true"
              testOnBorrow="true"
              testOnReturn="false"
              validationQuery="SELECT 1"
              timeBetweenEvictionRunsMillis="30000"
              maxActive="15"
              maxIdle="10"
              minIdle="5"
              removeAbandonedTimeout="60"
              removeAbandoned="false"
              logAbandoned="true"
              minEvictableIdleTimeMillis="30000"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
              username="root"
              password="123"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/broadleaf&quo