Springboot H2 Hibernate错误

时间:2017-09-19 10:02:21

标签: hibernate jpa heroku spring-boot h2

我正在使用部署在Heroku上的Springboot应用程序,但我无法使用H2。我收到了有关Url Datasource和Wrong Password and Username的几个错误。我正在尝试自动创建实体表。

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本地Web执行日志

  

11:50:48 web.1 | 2017-09-19 11:50:48.872 INFO 12876 --- [
  main] com.example.Main:以下   配置文件是活动的:生产11:50:49 web.1 | 2017年9月19日   11:50:49.078 INFO 12876 --- [主要]   ationConfigEmbeddedWebApplicationContext:刷新   org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7e32c033:   启动日期[Tue Sep 19 11:50:49 CEST 2017];背景的根源   层次11:50:50 web.1 | 2017-09-19 11:50:50.612 INFO 12876 ---   [main] o.s.b.f.s.DefaultListableBeanFactory:   覆盖bean' dataSource'的bean定义与众不同   定义:替换[Root bean:class [null];范围=;   抽象= FALSE; lazyInit = FALSE; autowireMode = 3; dependencyCheck = 0;   autowireCandidate = TRUE;初级= FALSE;   factoryBeanName = org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration $阿光;   factoryMethodName =数据源; initMethodName = NULL;   destroyMethodName =(推断)11:50:50 web.1 | > ;在课堂上定义   路径资源   [组织/ springframework的的/ boot /自动配置/ JDBC / DataSourceConfiguration $ Hikari.class]   用[Root bean:class [null];范围=;抽象= FALSE; lazyInit = FALSE;   autowireMode = 3; dependencyCheck = 0; autowireCandidate = TRUE;   初级= FALSE;   factoryBeanName = org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration $ Tomcat的;   factoryMethodName =数据源; initMethodName = NULL;   destroyMethodName =(推断);在类路径资源中定义   [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 --- [主要]   f.a.AutowiredAnnotationBeanPostProcessor:JSR-330   ' javax.inject.Inject'找到并支持自动装配的注释   11:50:51 web.1 | 2017-09-19 11:50:51.858 INFO 12876 --- [
  main] trationDelegate $ BeanPostProcessorChecker:Bean   ' org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration'   类型   [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration $$ EnhancerBySpringCGLIB $$ 338a41d7]   不适合所有BeanPostProcessors处理(for   例如:不符合自动代理的条件)11:50:52 web.1 |   2017-09-19 11:50:52.373 INFO 12876 --- [主要]   s.b.c.e.t.TomcatEmbeddedServletContainer:初始化为Tomcat   port(s):5000(http)11:50:52 web.1 | 2017-09-19 11:50:52.425 INFO   12876 --- [main] o.apache.catalina.core.StandardService:   启动服务Tomcat 11:50:52 web.1 | 2017-09-19 11:50:52.427   INFO 12876 --- [主要]   org.apache.catalina.core.StandardEngine:启动Servlet引擎:   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]。[/]:   初始化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:   初始化完成于3575 ms 11:50:53 web.1 | 2017年9月19日   11:50:53.228 INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.ServletRegistrationBean:映射servlet:   ' DispatcherServlet的'到[/] 11:50:53 web.1 | 2017-09-19 11:50:53.234   INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.ServletRegistrationBean:映射servlet:   ' webServlet'到[/ h2 / ] 11:50:53 web.1 | 2017-09-19 11:50:53.256   INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   ' 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:映射过滤器:   ' characterEncodingFilter' to:[/ ] 11:50:53 web.1 | 2017年9月19日   11:50:53.257 INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   ' hiddenHttpMethodFilter' to:[/ ] 11:50:53 web.1 | 2017年9月19日   11:50:53.257 INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   ' httpPutFormContentFilter' to:[/ ] 11:50:53 web.1 | 2017年9月19日   11:50:53.257 INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   ' RequestContextFilter两个' to:[/ ] 11:50:53 web.1 | 2017年9月19日   11:50:53.258 INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   ' webRequestLoggingFilter' to:[/ ] 11:50:53 web.1 | 2017年9月19日   11:50:53.271 INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   ' applicationContextIdFilter' to:[/ ] 11:50:53 web.1 | 2017年9月19日   11:50:53.273 INFO 12876 --- [ost-startStop-1]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   ' resourceUrlEncodingFilter' to:[/ *] 11:50:54 web.1 | 2017年9月19日   11:50:54.251错误12876 --- [主要]   o.a.tomcat.jdbc.pool.ConnectionPool:无法创建初始化   游泳池的连接。 11:50:54 web.1 | org.h2.jdbc.JdbcSQLException:   用户名或密码错误[28000-193] 11:50:54 web.1 |在   org.h2.message.DbException.getJdbcSQLException(DbException.java:345)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.message.DbException.get(DbException.java:179)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.message.DbException.get(DbException.java:155)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.message.DbException.get(DbException.java:144)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.engine.Engine.validateUserAndPassword(Engine.java:336)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.engine.Engine.createSessionAndValidate(Engine.java:162)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.engine.Engine.createSession(Engine.java:137)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.engine.Engine.createSession(Engine.java:27)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:349)〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.jdbc.JdbcConnection。(JdbcConnection.java:115)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.jdbc.JdbcConnection。(JdbcConnection.java:99)   〜[h2-1.4.193.jar!/:na] 11:50:54 web.1 |在   org.h2.Driver.connect(Driver.java:69)〜[h2-1.4.193.jar!/:na] 11:50:54   web.1 |在   org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)   〜[tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)   〜[tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:732)   [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:664)   [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:479)   [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.ConnectionPool。(ConnectionPool.java:154)   [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)   [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)   [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)   [tomcat-jdbc-8.5.11.jar!/:na] 11:50:54 web.1 |在   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 |     在   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 |     在   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 |     在   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 |     在   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 |在   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 |在   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 |在   org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration $$ EnhancerBySpringCGLIB $$ 9d10a5f7.CGLIB $ jpaVendorAdapter $ 4()   [弹簧引导自动配置-1.5.2.RELEASE.jar /:1.5.2.RELEASE]

例如我的测试使用H2仪表板,使用空密码和用户。我在概念上遗漏了什么吗?

修改

enter image description here

1 个答案:

答案 0 :(得分:0)

您忘记了数据库凭据,请查看堆栈跟踪

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

添加到您的application.properties

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

默认应该是用户:" sa"并传递:""空字符串,如果我没有被误认为是h2