1
votes

I am using a Springboot application deployed on Heroku, but I am unable to use H2. I obtain several errors regarding to Url Datasource and Wrong Password and Username. I am trying to create automatically entity table.

Main.java

@Controller
@EnableScheduling
@SpringBootApplication
public class Main {

  public static void main(String[] args) throws Exception {
    SpringApplication.run(Main.class, args);
  }

 }

UserConfiguration.java

@Entity
@Table(name = "UserConfiguration")
public class UserConfiguration {

    @Id
    private Long id;
    private float btcValue;
    private boolean sell;

    protected UserConfiguration() {}

    public UserConfiguration(Long id, float btcValue, boolean sell) {
        this.id = id;
        this.btcValue = btcValue;
        this.sell = sell;
    }
 ...
}

application.properties

# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2

# Datasource
spring.datasource.url=jdbc:h2:~/database
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=
spring.datasource.password=


###
#   Hibernate Settings
###
spring.jpa.hibernate.ddl-auto = create
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

Heroku Local Web Execution Log

11:50:48 web.1 | 2017-09-19 11:50:48.872 INFO 12876 --- [
main] com.example.Main : The following profiles are active: production 11:50:49 web.1 | 2017-09-19 11:50:49.078 INFO 12876 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7e32c033: startup date [Tue Sep 19 11:50:49 CEST 2017]; root of context hierarchy 11:50:50 web.1 | 2017-09-19 11:50:50.612 INFO 12876 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'dataSource' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred) 11:50:50 web.1 | > ; defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconf 11:50:50 web.1 | > igure/jdbc/DataSourceConfiguration$Tomcat.class]] 11:50:51 web.1 | 2017-09-19 11:50:51.346 INFO 12876 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 11:50:51 web.1 | 2017-09-19 11:50:51.858 INFO 12876 --- [
main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$338a41d7] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 11:50:52 web.1 | 2017-09-19 11:50:52.373 INFO 12876 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 5000 (http) 11:50:52 web.1 | 2017-09-19 11:50:52.425 INFO 12876 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 11:50:52 web.1 | 2017-09-19 11:50:52.427 INFO 12876 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.11 11:50:52 web.1 | 2017-09-19 11:50:52.650 INFO 12876 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 11:50:52 web.1 | 2017-09-19 11:50:52.650 INFO 12876 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3575 ms 11:50:53 web.1 | 2017-09-19 11:50:53.228 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 11:50:53 web.1 | 2017-09-19 11:50:53.234 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'webServlet' to [/h2/] 11:50:53 web.1 | 2017-09-19 11:50:53.256 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/] 11:50:53 web.1 | 2017-09-19 11:50:53.257 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/] 11:50:53 web.1 | 2017-09-19 11:50:53.257 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/] 11:50:53 web.1 | 2017-09-19 11:50:53.257 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/] 11:50:53 web.1 | 2017-09-19 11:50:53.257 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/] 11:50:53 web.1 | 2017-09-19 11:50:53.258 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/] 11:50:53 web.1 | 2017-09-19 11:50:53.271 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/] 11:50:53 web.1 | 2017-09-19 11:50:53.273 INFO 12876 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'resourceUrlEncodingFilter' to: [/*] 11:50:54 web.1 | 2017-09-19 11:50:54.251 ERROR 12876 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool. 11:50:54 web.1 | org.h2.jdbc.JdbcSQLException: Wrong user name or password [28000-193] 11:50:54 web.1 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.message.DbException.get(DbException.java:179) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.message.DbException.get(DbException.java:155) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.message.DbException.get(DbException.java:144) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.engine.Engine.validateUserAndPassword(Engine.java:336) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.engine.Engine.createSessionAndValidate(Engine.java:162) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.engine.Engine.createSession(Engine.java:137) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.engine.Engine.createSession(Engine.java:27) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:349) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:115) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:99) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.h2.Driver.connect(Driver.java:69) ~[h2-1.4.193.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) ~[tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) ~[tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:732) [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:664) [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:479) [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.ConnectionPool.(ConnectionPool.java:154) [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 | at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) [spring-jdbc-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] 11:50:54 web.1 | at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) [spring-jdbc-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] 11:50:54 web.1 | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:326) [spring-jdbc-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] 11:50:54 web.1 | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:366) [spring-jdbc-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] 11:50:54 web.1 | at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72) [spring-boot-autoconfigure-1.5.2.RELEASE.jar!/:1.5.2.RELEASE] 11:50:54 web.1 | at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139) [spring-boot-autoconfigure-1.5.2.RELEASE.jar!/:1.5.2.RELEASE] 11:50:54 web.1 | at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105) [spring-boot-autoconfigure-1.5.2.RELEASE.jar!/:1.5.2.RELEASE] 11:50:54 web.1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$9d10a5f7.CGLIB$jpaVendorAdapter$4() [spring-boot-autoconfigure-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]

As example my test using H2 dashboard, using empty password and user. Am I missing something conceptually?

EDIT

enter image description here

1

1 Answers

0
votes

You forgot db credentials, look at the stacktrace

org.h2.jdbc.JdbcSQLException: Wrong user name or password

add to your application.properties

spring.datasource.username=(h2 user)
spring.datasource.password=(h2 password)

Default should be user: "sa" and pass: "" empty string if i'm not mistaken for h2