Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRebekah Smith
7,263 PointsHeroku does not support H2 as a datasource, only PostGreSQL. Why does Chris's weather demo work with Heroku?
On Windows the Heroku deployment was slow and painful, and only to discover afterwards that Heroku does not support H2.
My error after deploy:
2017-06-21T21:58:25.639583+00:00 app[web.1]: 2017-06-21 21:58:25.639 WARN 4 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/rebekahperkins/website/config/DataConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Here Heroku serves up Chris's weather demo even though the datasource is configured for H2: https://teamtreehouse.com/library/deploying-to-heroku
3 Answers
Seth Kroger
56,414 PointsQuite often the database server and the app server are separate. This is almost always true with Heroku. The database is an add-on and you have to supply the database server's URL through config variables. The "almost always" part is where Chris pulled a little trick to sneak in H2. H2 is written in Java and runs on the JVM. What Chris does is install and run H2 through the same JVM as the Spring Boot app so they are running together on the same app server.
J Tan
11,847 PointsHow do I deploy H2 on the same JVM as Spring Boot? The workshop is not clear how thats done. Or is the fact that the properties file has localhost automatically handles deploying H2 on the same JVM?
Seth Kroger
56,414 PointsIt's a runtime dependency in the build.gradle file.
J Tan
11,847 PointsSeth Kroger I think this is the build.gradle file you're referring to: https://github.com/treehouse-projects/spring-unit-test-weather/blob/master/build.gradle
runtime 'com.h2database:h2'