복붙노트

[SPRING] Spring 부트 H2 콘솔 액세스

SPRING

Spring 부트 H2 콘솔 액세스

기본 Spring Boot app, 임베디드 Tomcat, Thymeleaf 템플릿 엔진이 있습니다. 콘솔에 액세스하기 위해이 빈을 작성했습니다.

@Bean
    public ServletRegistrationBean h2ConsoleServletRegistration() {
        ServletRegistrationBean bean = new ServletRegistrationBean(new WebServlet());
        bean.addUrlMappings("/console/*");
        return bean;
    }

하지만 콘솔 http : // localhost : 8080 / appContext / console / login.do에 액세스 할 때? jsessionid = f3585792a9bf1f0cf1a0b6a09dcefe1a

나는 다음과 같이 주석이 달린 콩을 가지고있다 :

@Entity
@Table(name="t_user")
public class User implements Serializable, UserDetails {
..
}

내 응용 프로그램 속성 :

spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

hibernate.dialect=org.hibernate.dialect.H2Dialect

JPA에서 만든 테이블은 보이지 않습니다.

해결법

  1. ==============================

    1.등록 정보 파일에있는 것을 모두 제거하십시오. 언급 한 모든 사람들은 불이행입니다. Springboot는 사용자의 h2 종속성을 식별하는대로 즉시 구성합니다. 또한 ServletRegistration 빈이 필요 없다. 그것을 제거하십시오. 이 파일을 속성 파일에 넣기 만하면됩니다. spring.h2.console.enabled = true

    등록 정보 파일에있는 것을 모두 제거하십시오. 언급 한 모든 사람들은 불이행입니다. Springboot는 사용자의 h2 종속성을 식별하는대로 즉시 구성합니다. 또한 ServletRegistration 빈이 필요 없다. 그것을 제거하십시오. 이 파일을 속성 파일에 넣기 만하면됩니다. spring.h2.console.enabled = true

    기본적으로 콘솔은 http : // localhost : 8080 / h2-console에서 액세스 할 수 있습니다. 기본 경로는 h2-console입니다. 다음을 사용하여 구성 할 수 있습니다. spring.h2.console.path 속성

  2. ==============================

    2.다음을보십시오 : https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

    다음을보십시오 : https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

    이 속성을 설정해보십시오.

    spring.jpa.hibernate.ddl-auto=create
    
  3. ==============================

    3.우선, H2 콘솔에 액세스하기 위해 Bean을 명시 적으로 정의 할 필요가 없습니다. 그것은 이미 Springboot에 의해 조심스럽게 처리됩니다. 다음과 같이 application.properties에서 H2 Console 경로를 정의 할 수 있습니다.

    우선, H2 콘솔에 액세스하기 위해 Bean을 명시 적으로 정의 할 필요가 없습니다. 그것은 이미 Springboot에 의해 조심스럽게 처리됩니다. 다음과 같이 application.properties에서 H2 Console 경로를 정의 할 수 있습니다.

    spring.h2.path = / h2-console

    다음을 통해 콘솔에 액세스 할 수 있습니다.

    http : // host : port / h2-console

    두 번째로 create는 기존 스키마를 삭제할 것이기 때문에 항상 "create"가 아닌 "update"로 ddl-auto 속성을 사용하십시오.

    spring.jpa.hibernate.ddl-auto = update

    Spring 부트와 H2 (Hiberante Enver를 보너스로 사용하는) 스타터 프로젝트를 찾고 있다면 원하지 않는다면 엔 버 패키지와 @Audited를 엔티티에서 제거하십시오. - 다음 중 하나를 시도해보십시오 :

    https://github.com/sundarsy/springboot-h2-enver

  4. ==============================

    4.pom.xml에 devtools 의존성이있는 경우 http : // localhost : 8080 / h2-console과 같은 기본 경로를 사용하여 H2 콘솔에 액세스 할 수 있습니다. 그렇지 않으면 아래와 같이 application.properties에 H2의 경로를 지정해야합니다.

    pom.xml에 devtools 의존성이있는 경우 http : // localhost : 8080 / h2-console과 같은 기본 경로를 사용하여 H2 콘솔에 액세스 할 수 있습니다. 그렇지 않으면 아래와 같이 application.properties에 H2의 경로를 지정해야합니다.

    devtools는 http : // localhost : 8080 / h2-console /에서 액세스 할 수 있습니다.

    POM : spring-boot-starter, h2, spring-boot-starter-web, spring-boot-devtools

    devtools가 없으면 속성에서 설정해야합니다.

    spring.h2.console.enabled=true 
    spring.h2.console.path=/h2-console
    

    POM : spring-boot-starter, h2, spring-boot-starter-web

    이것은 Spring Boot 2.1.1이 다른 사람들에게 도움이 될 수있는 경우였습니다.

  5. from https://stackoverflow.com/questions/43952259/springboot-accessing-h2-console by cc-by-sa and MIT license