Documentation Home
Time will vary depending on connection speed, etc.
This will take
10 mins.

Running the Heat Clinic locally

Goals

This tutorial is designed to get the Heat Clinic running in your local environment using the command prompt for your operating system. By the end of this tutorial you will have the consumer-facing Heat Clinic store running locally, as well as, the Broadleaf admin, which is used to manage the Heat Clinic data.

Prerequisites

First, download the Java 8 Development Kit: either the official Oracle JDK or Open JDK
You will also need the latest version of Maven (at least version 3.3.3, version 3.5.0 is recommended)

Need help installing the pre-requisites on Windows, OSX, or Linux?


Steps

Now that all of the pre-requisites are installed, let's set up the Heat Clinic.

  1. Install Broadleaf

    Download the Community Edition.

    a. Download the Community Edition. {Qualifying customers} can use this edition without charge, even in production. Anyone can use it to get hands on with core Broadleaf concepts including domain, extension patterns, and more in non-production environments.

    b. Once you have the correct version of the Heat Clinic downloaded, unzip it and keep note of the location.

    c. At the command line for your operating system, change your directory to where the Heat Clinic is unzipped. Type mvn install and hit enter.

    This might take a while as all of the Broadleaf dependencies and other transitive dependencies are downloaded

  2. Start the Admin

    Now let's start up the Heat Clinic admin by going into the admin directory from the command line and executing:

    » mvn spring-boot:run
    

    Once this has finished executing, you should be able to see the Heat Clinic Admin by going to http://localhost:8081/admin in your browser. The username and password is admin/admin.

  3. Start the Site

    After this is complete, start up the Heat Clinic frontend by going into the site directory from the command line and executing:

    » mvn spring-boot:run
    

    Once this has finished executing, you should be able to see the Heat Clinic by going to http://localhost:8080 in your browser

  4. Start the API

    There is an api project that just contains the Broadleaf APIs. Go into the api directory from the command line and execute:

    » mvn spring-boot:run
    

    Once this has finished, you can see the Swagger API definitions by going to http://localhost:8082/api/v1/swagger-ui.html.

    The APIs start up with a default username of broadleafapi and a randomly-generated password that shows up in your logs. You can change this by modifying the security information in ApiSecurityConfig in your demo project. To use this with Swagger, hit the "Authorize" button on the top right.


Next Steps

Now that you have Broadleaf up and running, here are some places you might go to next:


FAQ

Where is the Heat Clinic data stored? (Show Answer)

The Heat Clinic starts up with an embedded HSQL database, stored as a flatfile within the java.io.tmpdir directory. With INFO logging turned on, on startup you can see where the database file is:

2017-05-18 09:25:40.553  INFO 90729 --- [ost-startStop-1] c.b.autoconfigure.HSQLDBServer           : Starting HSQL server...
2017-05-18 09:25:40.554  WARN 90729 --- [ost-startStop-1] c.b.autoconfigure.HSQLDBServer           : HSQL embedded database server is for demonstration purposes only and is not intended for production usage.
[Server@447bcb66]: [Thread[localhost-startStop-1,5,main]]: checkRunning(false) entered
[Server@447bcb66]: [Thread[localhost-startStop-1,5,main]]: checkRunning(false) exited
[Server@447bcb66]: Initiating startup sequence...
[Server@447bcb66]: Server socket opened successfully in 4 ms.
[Server@447bcb66]: Database [index=0, id=0, db=file:/var/folders/5p/x301ksy93b5797hsck79gf_80000gn/T/broadleaf-hsqldb/broadleaf, alias=broadleaf] opened sucessfully in 464 ms.
[Server@447bcb66]: Startup sequence completed in 470 ms.
[Server@447bcb66]: 2017-05-18 09:25:41.042 HSQLDB server 2.3.3 is online on port 9001
[Server@447bcb66]: To close normally, connect and execute SHUTDOWN SQL
[Server@447bcb66]: From command line, use [Ctrl]+[C] to abort abruptly

You can modify this directory with the property demo.database.workingDirectory.

You can browse this database via Connect to the Local Database. You can also switch to another database such as Oracle, MySQL, Postgres or SQLServer.

Why did my data get wiped after a reboot? (Show Answer)

By default the Heat Clinic is configured to drop all tables and re-run import scripts on startup in the development runtime environment (the default for local development). In site/src/main/resources/runtime-properties/development.properties and also in admin/src/main/resources/runtime-properties/development.properties you will find these properties:

blPU.hibernate.hbm2ddl.auto=
blEventPU.hibernate.hbm2ddl.auto=
blSecurePU.hibernate.hbm2ddl.auto=
blEventPU.hibernate.hbm2ddl.auto=

There are 5 possible values for these properties:

  • validate - validate the database schema with the Hibernate data model, makes no changes to the database. Throws an exception if the database schema and the Hibernate model do not match
  • update - update the database schema with the Hibernate data model (e.g. add columns, foreign keys, tables). This will not change the underlying data inside the tables, but it is possible that you have invalid data after executing the update.
  • create - on startup, this executes a drop on all tables and data in the schema. Then all tables are re-created, and data load SQL is imported as specified by <unit_name>..hibernate.hbm2ddl.import_files like in development-shared.properties.
  • create-drop - on startup, do the same thing as the create value. On shutdown, drop the entire schema including all data and tables
  • none - do not do anything when comparing the Hibernate model to the database schema

You can also control whether or not the file itself that holds the database is deleted with demo.database.clearState=true.

Where does the Heat Clinic get all of its data for initial load? (Show Answer)

All of the Broadleaf modules have sets of demo and admin security data. Each of these load scripts are within the individual Broadleaf dependency .jar files, usually in the config/bc/sql folder. If INFO logging is turned on for the class org.broadleafcommerce.common.extensibility.jpa.JPAPropertiesPersistenceUnitPostProcessor (which is the default) then you will see some output about what SQL files were inserted and their order. Example:

2017-05-18 08:22:19.766  INFO 78707 --- [ost-startStop-1] PAPropertiesPersistenceUnitPostProcessor : AutoImportStage.PRIMARY_FRAMEWORK_SECURITY
2017-05-18 08:22:19.766  INFO 78707 --- [ost-startStop-1] PAPropertiesPersistenceUnitPostProcessor : [order:1000] config/bc/sql/load_admin_permissions.sql,config/bc/sql/load_admin_roles.sql,config/bc/sql/load_admin_menu.sql
2017-05-18 08:22:19.766  INFO 78707 --- [ost-startStop-1] PAPropertiesPersistenceUnitPostProcessor : AutoImportStage.PRIMARY_PRE_MODULE_SECURITY
2017-05-18 08:22:19.766  INFO 78707 --- [ost-startStop-1] PAPropertiesPersistenceUnitPostProcessor : AutoImportStage.PRIMARY_MODULE_SECURITY
2017-05-18 08:22:19.766  INFO 78707 --- [ost-startStop-1] PAPropertiesPersistenceUnitPostProcessor : [order:3000] config/bc/sql/load_menu_admin_security.sql

How can I add more files to the Heat Clinic data load?

At this point, it is likely that you should start to version your database and move to Liquibase to manage your database updates. You can then write changelogs to apply updates that will automatically run across your team and whenever you move to new environments.

Alternatively, if you are not ready to go to Liquibase and would rather just tie some new SQL to the Broadleaf SQL import process, you can add a new @Configuration class with an AutoImportSQL bean within the core project like so:

@Configuration
@Conditional(ImportCondition.class)
public class MyDataLoad {

@Bean
public AutoImportSql blPrivateDemoTenantData() {
return new AutoImportSql(AutoImportPersistenceUnit.BL_PU,"/sql/mycustomfile.sql", AutoImportStage.PRIMARY_LATE);
}

}

Why do I see error messages like 'HHH000389: Unsuccessful: alter table ...'? (Show Answer)

When the Heat Clinic first starts up, you might see a lot of these types of error messages in your logs:

[ERROR] 08:38:08 SchemaExport [admin][][] - HHH000389: Unsuccessful: alter table BLC_PAYMENT_LOG drop constraint FKA43703453E2FC4F9
[ERROR] 08:38:08 SchemaExport [admin][][] - user lacks privilege or object not found: PUBLIC.BLC_PAYMENT_LOG
[ERROR] 08:38:08 SchemaExport [admin][][] - HHH000389: Unsuccessful: alter table BLC_PAYMENT_LOG drop constraint FKA43703457470F437
[ERROR] 08:38:08 SchemaExport [admin][][] - user lacks privilege or object not found: PUBLIC.BLC_PAYMENT_LOG
[ERROR] 08:38:08 SchemaExport [admin][][] - HHH000389: Unsuccessful: alter table BLC_PGTMPLT_FLDGRP_XREF drop constraint FK99D625F66A79BDB5
[ERROR] 08:38:08 SchemaExport [admin][][] - user lacks privilege or object not found: PUBLIC.BLC_PGTMPLT_FLDGRP_XREF

This is a known bug that exists in Hibernate. This only occurs when the schema has never been created before and the hbm2ddl.auto is set to create or create-drop. These messages are harmless and can safely be ignored.