Spring引导不会使用data.sql加载数据来初始化数据库

前端之家收集整理的这篇文章主要介绍了Spring引导不会使用data.sql加载数据来初始化数据库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图在Spring启动时加载一些数据,但数据没有加载到数据库,虽然我没有收到任何错误.下面是代码

spring:
  debug: true
  datasource:
  username: root
  password: ****
  url: jdbc:mariadb://localhost:3306/customer_registration_service?connectTimeout=100
  driver-class-name: org.mariadb.jdbc.Driver
  initialize: true
  data: data-MysqL.sql
  validation-query: SELECT 1
  test-on-borrow: true
jpa:
  database-platform: org.hibernate.dialect.MysqL5InnoDBDialect
  properties:
    hibernate:
      ddl-auto: validate
      naming-strategy: org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy

我在src / main / resources下有data-MysqL.sql

为了强制错误,我试图故意给出一个错误文件名,但我仍然没有得到任何真正的错误.所以看起来Spring完全忽略了这个设置

编辑:

这是启动日志

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building customer-registration 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) @ customer-registration >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ customer-registration ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ customer-registration ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ customer-registration ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/cheruveettilz/Projects/innovationday/customer-registration-service/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ customer-registration ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) @ customer-registration <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) @ customer-registration ---

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__,| / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.2.RELEASE)

2017-07-13 19:41:37.055  INFO 83740 --- [           main] c.b.s.customer.registration.Application  : Starting Application 
2017-07-13 19:41:37.058  INFO 83740 --- [           main] c.b.s.customer.registration.Application  : No active profile set,falling back to default profiles: default
2017-07-13 19:41:37.106  INFO 83740 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4883e67d: startup date [Thu Jul 13 19:41:37 CEST 2017]; root of context hierarchy
2017-07-13 19:41:37.792  INFO 83740 --- [           main] o.s.b.f.s.DefaultListablebeanfactory     : Overriding bean definition for bean 'httpRequestHandlerAdapter' 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.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factorybeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2017-07-13 19:41:38.278  INFO 83740 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$4b8a61c9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-13 19:41:38.521  INFO 83740 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-07-13 19:41:38.530  INFO 83740 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-07-13 19:41:38.531  INFO 83740 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.11
2017-07-13 19:41:38.598  INFO 83740 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-07-13 19:41:38.598  INFO 83740 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1495 ms
2017-07-13 19:41:38.713  INFO 83740 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-07-13 19:41:38.716  INFO 83740 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-07-13 19:41:38.716  INFO 83740 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-07-13 19:41:38.716  INFO 83740 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-07-13 19:41:38.716  INFO 83740 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-07-13 19:41:39.080  INFO 83740 --- [           main] j.LocalContainerEntityManagerfactorybean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-07-13 19:41:39.094  INFO 83740 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2017-07-13 19:41:39.163  INFO 83740 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-07-13 19:41:39.165  INFO 83740 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-07-13 19:41:39.166  INFO 83740 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-07-13 19:41:39.206  INFO 83740 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-07-13 19:41:39.315  INFO 83740 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MysqL5InnoDBDialect
2017-07-13 19:41:39.841  INFO 83740 --- [           main] j.LocalContainerEntityManagerfactorybean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-07-13 19:41:40.513  INFO 83740 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4883e67d: startup date [Thu Jul 13 19:41:37 CEST 2017]; root of context hierarchy
2017-07-13 19:41:40.575  INFO 83740 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntityMetadata()
2017-07-13 19:41:40.831  INFO 83740 --- [           main] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile],methods=[OPTIONS]}" onto public org.springframework.http.HttpEntity
最佳答案
尝试在application.properties中添加此行:

spring.datasource.initialization-mode=always
原文链接:https://www.f2er.com/spring/431984.html

猜你在找的Spring相关文章