博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
broadleaf commerce到mysql和tomcat的迁移
阅读量:4973 次
发布时间:2019-06-12

本文共 9030 字,大约阅读时间需要 30 分钟。

    近期刚刚接触broadleaf commerce, 一个电商站点的开源模版。详细的执行和配置能够參考链接:

而该模版是在jetty容器下执行的,数据库是HSQL。官方站点上给出了怎样将数据库迁移到mysql以及把项目project部署在tomcat中所须要的配置,可是过程不甚具体,网上这方面的资源也不是非常多,所以楼主就打算写这篇博客作为一个总结。

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

(a)打开DemoSiteproject的根文件夹下pom.xml文件,在<dependencyManagement>区域中加入:

mysql
mysql-connector-java
5.1.26
jar
compile
(b)分别在admin和site目录中找到pom.xml打开并在
<dependencies>区域中加入:

mysql
mysql-connector-java

(c)在mysql数据库中加入database名为broadleaf

(d)改动admin/src/main/webapp/WEB-INF/jetty-env.xml和site/src/main/webapp/WEB-INF/jetty-env.xml文件。将其内容改为

jdbc/web
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/broadleaf
root
123
jdbc/secure
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/broadleaf
root
123
jdbc/storage
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/broadleaf
root
123

(e)分别打开admin/src/main/webapp/META-INF和admin/src/main/webapp/META-INF中的context.xml,将内容替换例如以下(数据库相关的配置信息如username和password请依据自身的环境作对应的改动):

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.HSQLDialectblCMSStorage.hibernate.dialect=org.hibernate.dialect.HSQLDialectblSecurePU.hibernate.dialect=org.hibernate.dialect.HSQLDialect

分别替换为:

blPU.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialectblSecurePU.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialectblCMSStorage.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

(f)打开DemoSite根文件夹下的build.properties,将例如以下内容

ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.HSQLDialectant.blPU.url=jdbc:hsqldb:hsql://localhost/broadleafant.blPU.userName=saant.blPU.password=nullant.blPU.driverClassName=org.hsqldb.jdbcDriverant.blSecurePU.url=jdbc:hsqldb:hsql://localhost/broadleafant.blSecurePU.userName=saant.blSecurePU.password=nullant.blSecurePU.driverClassName=org.hsqldb.jdbcDriverant.blCMSStorage.url=jdbc:hsqldb:hsql://localhost/broadleafant.blCMSStorage.userName=saant.blCMSStorage.password=nullant.blCMSStorage.driverClassName=org.hsqldb.jdbcDriver

依据自己数据库的配置改动为:

ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.MySQL5InnoDBDialectant.blPU.url=jdbc:mysql://localhost:3306/broadleafant.blPU.userName=rootant.blPU.password=123ant.blPU.driverClassName=com.mysql.jdbc.Driverant.blSecurePU.url=jdbc:mysql://localhost:3306/broadleafant.blSecurePU.userName=rootant.blSecurePU.password=123ant.blSecurePU.driverClassName=com.mysql.jdbc.Driverant.blCMSStorage.url=jdbc:mysql://localhost:3306/broadleafant.blCMSStorage.userName=rootant.blCMSStorage.password=123ant.blCMSStorage.driverClassName=com.mysql.jdbc.Driver

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

2.server的迁移(从jetty到tomcat7)

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

org.apache.tomcat.maven
tomcat7-maven-plugin
2.0
${webappDirectory}
/
${httpPort}
${httpsPort}
${webappDirectory}/WEB-INF/blc-example.keystore
broadleaf
broadleaf
 

(b)在eclipse中右键DemoSiteproject,先后执行Run As里面的Maven clean和Maven install,成功后就会在DemoSite中的admin和site的target目录中有对应的war包生成,楼主生成的两个war包名为admin.war和zk.war。

(c)楼主的环境是ubuntu。tomcatserver中webapps的路径为/var/lib/tomcat7/webapps,将admin和zk.war复制到该文件夹下,然后重新启动tomcatserver:

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)中改动完毕后再重新启动tomcatserver:

sudo /etc/init.d/tomcat7 restart

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

转载于:https://www.cnblogs.com/claireyuancy/p/6879583.html

你可能感兴趣的文章
前端利器躬行记(2)——Babel
查看>>
前端利器躬行记(6)——Fiddler
查看>>
Forbidden You don't have permission to access / on this server.
查看>>
Intellij Idea新建web项目(转)
查看>>
用JAVA编写浏览器内核之实现javascript的document对象与内置方法
查看>>
centos iptables
查看>>
unity3d 移动与旋转 2
查看>>
寻找二叉查找树中比指定值小的所有节点中最大的那个节点
查看>>
如何设置输入框达到只读效果
查看>>
RT3070 USB WIFI 在连接socket编程过程中问题总结
查看>>
MIS外汇平台荣获“2013年全球最佳STP外汇交易商”
查看>>
LeetCode 题解之Add Digits
查看>>
hdu1502 , Regular Words, dp,高精度加法
查看>>
20120227_CET6
查看>>
SpringBoot在idea中的热部署配置
查看>>
MyEclipse连接SQL Server 2008数据库的操作方法
查看>>
leetcode【67】-Bulb Switcher
查看>>
JS验证图片格式和大小并预览
查看>>
laravel5.2 移植到新服务器上除了“/”路由 ,其它路由对应的页面显示报404错误(Object not found!)———新装的LAMP没有加载Rewrite模块...
查看>>
编写高质量代码--改善python程序的建议(六)
查看>>