broadleaf commerce到mysql和tomcat的迁移_MySQL
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>
<dependencies></dependencies>
区域中添加:<dependency><groupid>mysql</groupid><artifactid>mysql-connector-java</artifactid></dependency>
(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' #注意:单引号不能省略
set JAVA_OPTS=-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256M #注意:无单引号
sudo /etc/init.d/tomcat7 restart

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings
