search
HomeDatabaseMysql Tutorialbroadleaf commerce到mysql和tomcat的迁移_MySQL

broadleaf commerce到mysql和tomcat的迁移_MySQL

Jun 01, 2016 pm 01:15 PM
mysqlOfficial websiteworkdatabaseE-commerce

Tomcat

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

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

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

(a)打开DemoSite工程的根目录下pom.xml文件,在<dependencymanagement>区域中添加:</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></dependencies>区域中添加:
<dependency><groupid>mysql</groupid><artifactid>mysql-connector-java</artifactid></dependency>
(c)在mysql数据库中添加database名为broadleaf(d)分别打开admin/src/main/webapp/META-INF和<code>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><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><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"></resource></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
sudo /etc/init.d/tomcat7 restart

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

2.服务器的迁移(从jetty到tomcat7)(a)在site和admin目录下的pom.xml文件的中<plugins>区域中分别添加:</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>
<code>(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服务器的迁移也大功告成啦。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

How to use MySQL functions for data processing and calculationHow to use MySQL functions for data processing and calculationApr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

An efficient way to batch insert data in MySQLAn efficient way to batch insert data in MySQLApr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

Steps to add and delete fields to MySQL tablesSteps to add and delete fields to MySQL tablesApr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool