2017-05-08 75 views
1

我似乎無法弄清楚如何用Spring Boot配置H2的Web控制檯。我已經添加用Spring Boot配置H2的Web控制檯

spring.datasource.url=jdbc:h2:mem:myschema; 
spring.h2.console.enabled=true 
spring.h2.console.path=/console 

要我application.properties,但仍然沒有什麼位於localhost:8080 /控制檯。 H2的司機是我的類路徑中,所以我想這三個在the docs上市,我可能不會滿足的唯一條件是

你正在開發一個Web應用程序

究竟是什麼意思呢?我有spring-boot-starter-web作爲依賴於我的pom.xml,和我的開始/主標註有

@EnableAutoConfiguration 
@ComponentScan({"com.xxxx"}) 

我缺少什麼?

請注意,我不想使用MVC。

+0

這很奇怪。即使我在我的pom中也有同樣的東西(springboot,parent,spring-boot-starter-web,h2 dependency)。和/控制檯工作得很好。這裏是我的H2-依賴 com.h2database H2 運行 pvpkiran

回答

0

H2 webconsole自動配置僅在包含spring-web時觸發。

但是,所有你需要做的,開始H2 Web控制檯運行這段代碼

org.h2.tools.Server s = org.h2.tools.Server.createWebServer("-web","-webAllowOthers","-webDaemon","-webPort", "8080").start(); 
... 
s.stop(); // if you want to stop 

你也可以做的地方定義這個bean

@Bean(initMethod="start",destroyMethod="stop") 
public org.h2.tools.Server h2WebConsonleServer() throws SQLException { 
    return org.h2.tools.Server.createWebServer("-web","-webAllowOthers","-webDaemon","-webPort", "8080"); 
} 
相關問題