2015-11-13 2 views
0

Здравствуйте, я не в состоянии открыть h2-консоль с пружинными загрузкамиSpring загрузка h2-консоль не работает

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.0.RC1</version> 
</parent> 

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-devtools</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-thymeleaf</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.thymeleaf.extras</groupId> 
     <artifactId>thymeleaf-extras-springsecurity4</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.h2database</groupId> 
     <artifactId>h2</artifactId> 
     <scope>runtime</scope> 
    </dependency> 

SpringSecurity Cfg:

@Configuration 

@EnableWebSecurity общественного класса SecurityConfig расширяет WebSecurityConfigurerAdapter {

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
    auth.inMemoryAuthentication() 
     .withUser("admin").password("admin").roles("ADMIN").and() 
     .withUser("user").password("user").roles("USER"); 
} 

@Override 
protected void configure(HttpSecurity httpSecurity) throws Exception { 
    httpSecurity.authorizeRequests() 
    .anyRequest().authenticated() 
    .and() 
     .formLogin().loginPage("/login").permitAll() 
    .and() 
     .logout().permitAll() 
    .and() 
     .exceptionHandling().accessDeniedPage("/Access_Denied") 
    .and() 
     .csrf(); 
} 

@SpringBootApplication 

общественного класса SpringBootWebSecureApplication {

@Bean 
public Java8TimeDialect java8TimeDialect() { 
    return new Java8TimeDialect(); 
} 

public static void main(String[] args) { 
    SpringApplication.run(SpringBootWebSecureApplication.class); 
} 

}

Я начинаю с ботинок:

-Dserver.port=8090 
-Dspring.h2.console.enabled=true 
-Dspring.datasource.url=jdbc:h2:mem:testdb 
-Dspring.datasource.username=sa 
-Dspring.datasource.driverClassName=org.h2.Driver 

Журналы:

2015-11-13 17:37:47 [restartedMain] DEBUG c.m.a.SpringBootWebSecureApplication - Running with Spring Boot v1.3.0.RC1, Spring v4.2.2.RELEASE 
2015-11-13 17:37:49 [restartedMain] INFO o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 8090 (http) 
2015-11-13 17:37:50 [localhost-startStop-1] INFO o.s.b.c.e.ServletRegistrationBean - Mapping servlet: 'webServlet' to [/h2-console/*] 
2015-11-13 17:37:51 [localhost-startStop-1] INFO o.s.s.web.DefaultSecurityFilterChain - Creating filter chain: Ant [pattern='/h2-console/**'], [org.springframework.secu[email protected]11ffd6f0, org.spring[email protected]615c57c5, [email protected]cbf, org.[email protected]af7bece, org.springfram[email protected]17d03ab2, org.sp[email protected]613197b, org.springframework.[email protected]8d48442, org.springfram[email protected]7fa13240, o[email protected]9f16a1c, org[email protected]1f3f02ef, org.springfr[email protected]115de1f6] 

Но когда я открываю браузер с мое приложение консоль не появляется

http://localhost:8090/h2-console/ 

Любые намеки?

Спасибо

+0

Та же проблема здесь. Вы нашли решение? – Sailcomp

ответ

0

То же самое здесь, я думаю, что это Java8TimeDialect Bean, в вашем случае.

В моем случае у меня есть DandelionDialect Bean и , когда я удаляю его h2-console снова работает ... Попробуйте удалить Java8TimeDialect, чтобы узнать, работает ли консоль.

Что-то связанное с загрузкой весны DispatcherServletAutoConfiguration ?, порядок, в котором сервлеты создаются или отображаются? Не совсем уверен ...

0

Вы можете попробовать следующий класс конфигурации:

import org.h2.server.web.WebServlet; 
import org.springframework.boot.web.servlet.FilterRegistrationBean; 
import org.springframework.boot.web.servlet.ServletRegistrationBean; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.web.filter.ShallowEtagHeaderFilter; 

import javax.servlet.DispatcherType; 
import java.util.EnumSet; 

@Configuration 
public class WebConfiguration { 

    private static final String mapping = "/console/*"; 

    @Bean 
    public ServletRegistrationBean h2servletRegistration(){ 
     ServletRegistrationBean registrationBean = new ServletRegistrationBean(new WebServlet()); 
     registrationBean.addUrlMappings(mapping); 
     return registrationBean; 
    } 

    @Bean 
    public FilterRegistrationBean shallowEtagHeaderFilter() { 
     FilterRegistrationBean registration = new FilterRegistrationBean(); 
     registration.setFilter(new ShallowEtagHeaderFilter()); 
     registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class)); 
     registration.addUrlPatterns(mapping); 
     return registration; 
    } 

} 
Смежные вопросы