broadleaf commerce到mysql和tomcat的迁移

时间:2014-05-08 04:06:52   收藏:0   阅读:615

    最近刚刚接触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"/>

    <Resource name="jdbc/secure"
              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"/>
</Context>


(e)打开core/src/main/resources/runtime-properties/common-shared.properties文件,将以下的三条


blPU.hibernate.dialect=org.hibernate.dialect.HSQLDialect
blCMSStorage.hibernate.dialect=org.hibernate.dialect.HSQLDialect
blSecurePU.hibernate.dialect=org.hibernate.dialect.HSQLDialect


分别替换为:

blPU.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
blSecurePU.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
blCMSStorage.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect


(f)打开DemoSite根目录下的build.properties,将如下内容

ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.HSQLDialect

ant.blPU.url=jdbc:hsqldb:hsql://localhost/broadleaf
ant.blPU.userName=sa
ant.blPU.password=null
ant.blPU.driverClassName=org.hsqldb.jdbcDriver

ant.blSecurePU.url=jdbc:hsqldb:hsql://localhost/broadleaf
ant.blSecurePU.userName=sa
ant.blSecurePU.password=null
ant.blSecurePU.driverClassName=org.hsqldb.jdbcDriver

ant.blCMSStorage.url=jdbc:hsqldb:hsql://localhost/broadleaf
ant.blCMSStorage.userName=sa
ant.blCMSStorage.password=null
ant.blCMSStorage.driverClassName=org.hsqldb.jdbcDriver


根据自己数据库的配置修改为:

ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

ant.blPU.url=jdbc:mysql://localhost:3306/broadleaf
ant.blPU.userName=root
ant.blPU.password=123
ant.blPU.driverClassName=com.mysql.jdbc.Driver

ant.blSecurePU.url=jdbc:mysql://localhost:3306/broadleaf
ant.blSecurePU.userName=root
ant.blSecurePU.password=123
ant.blSecurePU.driverClassName=com.mysql.jdbc.Driver

ant.blCMSStorage.url=jdbc:mysql://localhost:3306/broadleaf
ant.blCMSStorage.userName=root
ant.blCMSStorage.password=123
ant.blCMSStorage.driverClassName=com.mysql.jdbc.Driver

这样数据库的迁移就完成了。

2.服务器的迁移(从jetty到tomcat7)

(a)在site和admin目录下的pom.xml文件的中<plugins>区域中分别添加:

                         <plugin>
                                <groupId>org.apache.tomcat.maven</groupId>
                                <artifactId>tomcat7-maven-plugin</artifactId>
                                <version>2.0</version>
                                <configuration>
                                        <warSourceDirectory>${webappDirectory}</warSourceDirectory>
                                        <path>/</path>
                                        <port>${httpPort}</port>
                                        <httpsPort>${httpsPort}</httpsPort>
                                        <keystoreFile>${webappDirectory}/WEB-INF/blc-example.keystore</keystoreFile>
                                        <keystorePass>broadleaf</keystorePass>
                                        <password>broadleaf</password>
                                </configuration>
                        </plugin>

(b)在eclipse中右键DemoSite工程,先后运行Run As里面的Maven clean和Maven install,成功后就会在DemoSite中的admin和site的target文件夹中有相应的war包生成,楼主生成的两个war包名为admin.war和zk.war。

(c)楼主的环境是ubuntu,tomcat服务器中webapps的路径为/var/lib/tomcat7/webapps,将admin和zk.war拷贝到该目录下,然后重启tomcat服务器:

sudo /etc/init.d/tomcat7 restart
看到/var/log/tomcat7/catalina.out文件报错如下:

Caused by: java.lang.OutOfMemoryError: Java heap space
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:268)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:128)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2105)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1981)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1947)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1932)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1326)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5179)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1673)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        ... 4 more

百度了以后得知是内存溢出的问题,具体的解决方案如下:

ubuntu中修改catalina.sh文件(楼主该文件的路径是/usr/share/tomcat7/bin/catalina.sh),在文件首行添加如下内容:

JAVA_OPTS=‘-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256M‘ #注意:单引号不能省略

windows中修改catalina.bat文件,在第一行添加如下内容:

set JAVA_OPTS=-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256M #注意:无单引号

(d)按照(c)中修改完成后再重启tomcat服务器:

sudo /etc/init.d/tomcat7 restart

就可以在浏览器中正常打开电商页面:localhost:8080/zk和后台管理页面:localhost:8080/admin了,往tomcat服务器的迁移也大功告成啦。

broadleaf commerce到mysql和tomcat的迁移,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!