Page 1 of 1

Problem switching to MySQL

Posted: Fri Jun 19, 2015 9:29 pm
by blondeMatrix
Hello to the Broadleaf community,

I am attempting to build and deploy Broadleaf for evaluation. Building the project in IntelliJ IDEA seemed to go fine. The point where I run into difficulties is when configuring Broadleaf to use MySQL rather than HSQLDB. This is despite carefully following your documentation on the changeover (though I'm finding the directions rather unclear in places). I'm hoping that someone can help identify the cause/solution, based on the log output:

http://assets.optomus.com/documents/broadleaf.log

Happy to provide any configurations necessary to help solve.

Thanks & regards,

Chris.

Re: Problem switching to MySQL

Posted: Sun Jun 21, 2015 8:26 pm
by phillipuniverse
The log link didn't work for me.

Re: Problem switching to MySQL

Posted: Mon Jun 22, 2015 1:12 am
by blondeMatrix
Strange. Here is the link again (works for me):

http://assets.optomus.com/documents/broadleaf.log

Below I've pasted a snippet from the logs containing the first signs of trouble.

Code: Select all

[ WARN] 14:08:07 RuntimeEnvironmentPropertiesConfigurer - Unable to determine runtime environment, using default environment 'development'
[ WARN] 14:08:15 MergePersistenceUnitManager - A BroadleafClassTransformer is configured for this persistence unit, but Spring reported a problem (likely that a LoadTimeWeaver is not registered). As a result, the Broadleaf Commerce ClassTransformer (org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyClassTransformer) is not being registered with the persistence unit.
[ WARN] 14:08:15 MergePersistenceUnitManager - A BroadleafClassTransformer is configured for this persistence unit, but Spring reported a problem (likely that a LoadTimeWeaver is not registered). As a result, the Broadleaf Commerce ClassTransformer (org.broadleafcommerce.common.extensibility.jpa.convert.EntityMarkerClassTransformer) is not being registered with the persistence unit.
[ WARN] 14:08:15 MergePersistenceUnitManager - A BroadleafClassTransformer is configured for this persistence unit, but Spring reported a problem (likely that a LoadTimeWeaver is not registered). As a result, the Broadleaf Commerce ClassTransformer (org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyClassTransformer) is not being registered with the persistence unit.
[ WARN] 14:08:27 AbstractEhcacheRegionFactory - HHH020003: Could not find a specific ehcache configuration for cache named [blSandBoxElements]; using defaults.
[ WARN] 14:08:46 MergeXmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exporter' defined in resource loaded from byte array: Invocation of init method failed; nested exception is org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.apache.tomcat.dbcp.dbcp2.BasicDataSource@1672456] with key 'webStorageDS'; nested exception is javax.management.InstanceAlreadyExistsException: Catalina:type=DataSource,host=localhost,context=/,class=javax.sql.DataSource,name="jdbc/storage"

Re: Problem switching to MySQL

Posted: Mon Jun 22, 2015 1:24 pm
by phillipuniverse
What is in your web application context.xml, your Tomcat server context.xml and your Tomcat server server.xml? My hunch is that in META-INF/context.xml in your web application you have the same JNDI resources as your Tomcat server context.xml or server.xml. They should only exist in 1 place.

Also, it looks like you do not have a -javaagent:/path/to/spring-instrument.jar set in $CATALINA_OPTS (which is normally set in setenv.sh). This could impact future compatibility with Broadleaf 3rd-party module as this is assumed. There is a warning that references it at :

Code: Select all

[ WARN] 14:08:15 MergePersistenceUnitManager - A BroadleafClassTransformer is configured for this persistence unit, but Spring reported a problem (likely that a LoadTimeWeaver is not registered). As a result, the Broadleaf Commerce ClassTransformer

Re: Problem switching to MySQL

Posted: Mon Jun 22, 2015 9:29 pm
by blondeMatrix
Thanks Phillip,

You are correct - I had configured the three JNDI data sources in Tomcat's context.xml, as I had previously been unsuccessful in getting Broadleaf to connect to MySQL via Broadleaf's own context.xml. So I am back to the original problem, which you might be able to assist with. Firstly, thank you for your assistance thus far.

I placed the JDBC driver in...

DemoSite/lib/mysql-connector-java-5.1.35-bin.jar Right place?

And updated pom.xml with the following dependency...

Code: Select all

            <!-- Other dependencies -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.35</version>
            </dependency>


Yet, I get the following errors when attempting to run the application...

Code: Select all

23-Jun-2015 14:16:36.250 WARNING [RMI TCP Connection(2)-127.0.0.1] org.apache.naming.NamingContext.lookup Unexpected exception resolving reference
 java.sql.SQLException: ${database.driver}
   at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
...
Caused by: java.lang.ClassNotFoundException: ${database.driver}
...
23-Jun-2015 14:16:36.255 WARNING [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: javax.naming.NamingException: ${database.driver}
23-Jun-2015 14:16:36.267 WARNING [RMI TCP Connection(2)-127.0.0.1] org.apache.naming.NamingContext.lookup Unexpected exception resolving reference
 java.sql.SQLException: ${database.driver}
   at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
...
Caused by: java.lang.ClassNotFoundException: ${database.driver}


Incidentally, this same MySQL JDBC driver is also contained in Tomcat's own 'lib' folder. Seems to make no difference. Odd.

Re: Problem switching to MySQL

Posted: Thu Jun 25, 2015 3:03 pm
by phillipuniverse
DemoSite/lib/mysql-connector-java-5.1.35-bin.jar Right place?


No.

And updated pom.xml with the following dependency...


This is fine if you are using the embedded Tomcat plugin that is kicked off via the ant tasks. For instance, if you are running nat tomcat or ant tomcat-jrebel then MySQL needs to be a dependency of the embedded Tomcat plugin (as the HSQL plugin is currently).

Yet, I get the following errors when attempting to run the application...


Instead of hardcoding the database username, password or URL directly in context.xml, we have these JNDI resource definitions set up to get this information from JVM arguments.

If you look in build.xml in the site and/or admin projects, you will see these JVM arguments being set up in the tomcat task prior to invoking tomcat7:run:

<target name="tomcat" depends="start-db">
<delete dir="war/WEB-INF/lib"/>
<artifact:mvn mavenHome="${maven.home}" fork="true">
<jvmarg value="-XX:MaxPermSize=256M" />
<jvmarg value="-Xmx512M" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" />
<jvmarg value="-javaagent:${spring.instrument.path}" />
<jvmarg value="-Druntime.environment=${runtime.environment}" />
<jvmarg value="-Ddatabase.user=${database.user}" />
<jvmarg value="-Ddatabase.password=${database.password}" />
<jvmarg value="-Ddatabase.driver=${database.driver}" />
<jvmarg value="-Ddatabase.url=${database.url}" />
<arg value="compile"/>
<arg value="war:exploded"/>
<arg value="tomcat7:run"/>
</artifact:mvn>
</target>


These jvmarg parameters:

<jvmarg value="-Ddatabase.user=${database.user}" />
<jvmarg value="-Ddatabase.password=${database.password}" />
<jvmarg value="-Ddatabase.driver=${database.driver}" />
<jvmarg value="-Ddatabase.url=${database.url}" />


popuplate those system properties from ant properties, in this order (look at the top of build.xml for this code):

Code: Select all

<!-- See the following URL for a description of this property file strategy -->
<!-- The only difference is we prepend a . for the home directory property files -->
<!-- http://www.javaranch.com/ant/properties.jsp -->
<property file="${user.home}/.${project.name}.properties"/>
<property file="${user.home}/.build.properties"/>
<property name="config.filename" value="${user.name}.properties"/>
<property file="config/${config.filename}"/>
<property file="../build.properties"/>


If you're building a war and running on a standalone Tomcat instance (which is what I think that you're doing) then this is what you need to do:

1. Copy the mysql connector jar into the lib directory of Tomcat
2. Ensure that the CATALINA_OPTS environment variable sets database.user, database.driver, database.password and database.url. This is commonly set in setenv.sh (linux/osx) or setenv.bat (windows):

Code: Select all

export CATALINA_OPTS="
-Ddatabase.url=jdbc:mysql://localhost:3306/broadleaf
-Ddatabase.user=readwriteuser
-Ddatabase.password=databasepassword
-Ddatabase.driver=com.mysql.jdbc.Driver

-Druntime.environment=development

-XX:MaxPermSize=512M
-Xmx1024M

-javaagent:/path/to/spring-instrument-4.1.6.RELEASE.jar"

Re: Problem switching to MySQL

Posted: Tue Jul 14, 2015 10:07 pm
by blondeMatrix
Thanks Philip.

I deployed mycompany.war and admin.war to a standalone instance of Tomcat, and finally got Broadleaf working.  The Broadleaf guide on switching to MySQL stipulated a number of changes to Broadleaf configuration files prior to compiling the program and building the WARs. Actually, how much of this is really necessary if the intention is to deploy the WARs to a standalone instance of Tomcat anyway?

Regarding the defining of database parameters in setenv.sh/bat, I'm wondering if this is the best strategy when there may be more than one instance of Broadleaf running on the same Tomcat instance, or server. In such a case would you personally rather define the database connection in the two context.xml files contained in Broadleaf itself? I guess a third option is to place these in Tomcat's context.xml, but that would require changing the JNDI names to avoid any conflict when installing additional instances of Broadleaf.

Thanks & regards,

Chris.

Re: Problem switching to MySQL

Posted: Mon Jul 27, 2015 4:42 am
by phillipuniverse
Yeah, if you're deploying different Broadleaf instances to the same Tomcat container then you would have to change JNDI resource names anyway if you wanted them to point to different databases. And then I would still use setenv.sh to pass in those credentials, you'll just need to mostly duplicate them.

Actually, how much of this is really necessary if the intention is to deploy the WARs to a standalone instance of Tomcat anyway?


Not sure I understand your question here.

Re: Problem switching to MySQL

Posted: Tue Aug 11, 2015 2:04 am
by anonnihcas
I was trying to setup Broadleaf eCommerce in Apache Tomcat/MySQL/Win 10 environment, but I am not able to deploy the WAR. I had gone through the Broadleaf Blogs/Forums and also StackExchange for all possible solutions, but I am still not able to get the site/admin portal up and running.

Here are the steps which I had followed

Here is the Environment which I am working

    Server version: Apache Tomcat/8.0.24
    Server built: Jul 1 2015 20:19:55 UTC
    Server number: 8.0.24.0
    OS Name: Windows 8.1
    OS Version: 6.3
    Architecture: amd64
    Java Home: C:\Program Files\Java\jdk1.8.0_51\jre
    JVM Version: 1.8.0_51-b16
    JVM Vendor: Oracle Corporation
    CATALINA_BASE: E:\MyProject\apache-tomcat-8.0.24
    CATALINA_HOME: E:\MyProject\apache-tomcat-8.0.24

As per the instructions in the forum, have updated the Apache Tomcat global server.xml and context.xml

server.xml

Code: Select all

<GlobalNamingResources>
<!-- Editable user database that can also be used by
     UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
          type="org.apache.catalina.UserDatabase"
          description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />

 <Resource name="jdbc/broadleaf"
        auth="Container"
        type="javax.sql.DataSource"
        username="broadleaf"
        password="broadleaf"
        driverClassName="com.mysql.jdbc.Driver"
        description="Global Address Database"
        url="jdbc:mysql://localhost:3306/broadleaf"
        maxActive="15"
        maxIdle="3"/>


context.xml

Code: Select all

 <Resource name="jdbc/web" auth="Container" type="javax.sql.DataSource"
           maxActive="30" maxIdle="60" maxWait="10000"
           username="broadleaf" password="broadleaf" driverClassName="com.mysql.jdbc.Driver"
           connectionProperties="useUnicode=true;characterEncoding=utf8;"
           url="jdbc:mysql://localhost:3306/broadleaf?useUnicode=true&amp;characterEncoding=utf8"/>




I had downloaded the Demo site from Git and had modified the following properties(after running the ant build target to modify the site specific settings) and before running the Maven

build.properties

Code: Select all

database.user=broadleaf
database.password=broadleaf
database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/broadleaf?useUnicode=true&characterEncoding=utf8


build.xml in both admin and site has been changed to reflect the MySQL URL and DB connection parameters

Have also updated core\src\main\resources\runtime-properties\common-shared.properties to change from HSQL to MySQl

Code: Select all

blPU.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect


Have updated the context.xml in both site and admin to be in line with Apache Tomcat context.xml

Changed the pom.xml commenting out the hsql DB and added entries for MySQL DB. Also, copied the MySQL JAR to the lib folder

Changed jetty-env.xml(although in forums it is pointed out that jetty is ignored and entries in context.xml would be picked up).

The problem that I see is that it is able to create certain tables while certain set of tables are not created. Also, both the site and admin WAR's are not deployed. Any idea on what other parameters I need to change? Here is the link to log fileshttp://1drv.ms/1P1Zycd.